This is not a duplicate question.
Assume I have
- the full path
- to a regular file named
target
- that might be owned by some other user.
- and the environment may be stripped down (busybox with very little enabled)
In a shell script, how can I test whether this file is executable by its owner when I might not be its owner? Imagine that my program's purpose is to check if everything is set up nicely for other things to run (since the environment may have been ruined by other users) and it's looking in a particular directory to make sure the owners of every file have permission to execute their file.
This is a professional context, not homework.
Any solution I will use needs to cover all kinds of old Linux environments that I had no hand in setting up (so they could be missing things you'd normally expect like which
or some options on find
etc).
However, this question might be useful for others who don't face that limitation so I do appreciate other solutions that require more complete or modern environments.
[ -x "$path" ]
only tells me if I can execute it.
ls -l "$path"
and checking if the fourth character is x
seems too fragile: -rwxrw-rw- 1 otheruser group 26 Jun 13 10:57 target
ls -F "$path"
and checking if it ends in *
seems a little better: target*
The one environment I tested does take into account who the actual owner is... But this does not feel like the best way...