test -x /usr/bin/find
(or [ -x /usr/bin/find ]
) does not output anything. The test will be true if /usr/bin/find
is an existing executable file, and false if the pathname does not exist, or if it's not executable.
If test
exits successfully (with a zero exits status, signifying "no error"), the shell will execute the rest of the commands. If it exits with a failure (a non-zero exit status, signifying "some error"), exit 0
will terminate the current shell, preventing the rest of the commands from running.
It would arguably be better to use exit 1
or just exit
in place of exit 0
when find
can't be found in /usr/bin
though. Using exit 0
masks the exit status of test
(which would be non-zero), and prevents the caller of this script from being notified of the failure of finding find
at the given location.
Related to the fact that an exit status of zero evaluates to "true" when tested as a boolean in the shell:
Related to using ||
and &&
in general:
0
exit status means success and not failure as is the case in many other contexts. – terdon Jan 10 '22 at 10:15