Shell commands to determine if file is held on an APFS volume
I'd do the following:


Use a combination of basename (to get the full path of the file, if required) and df to determine which volume the file is on.
Use diskutil info to determine the filesystem type of the volume (you could also use mount).


There are perhaps better ways of doing it but that will certainly work.

The following one-liner was suggested by fd0 in a comment:

df -T apfs /absolute/path/to/file &gt;/dev/null &amp;&amp; Do Stuff


This executes "Do Stuff" only if the file is on an APFS filesystem. If Do Stuff is more than a few simple commands the same can be accomplished with

if df -T apfs /absolute/path/to/file &gt;/dev/null; then
    do stuff
    do even more stuff
fi