[ and test are synonyms (except [ requires ]), so you don't want to use [ test:
[ -x /bin/cat ] && echo cat'cat is executableexecutable' test -x /bin/cat && echo cat'cat is executableexecutable' test returns a zero exit status if the condition is true, otherwise nonzero. This can actually be replaced by any program to check its exit status, where 0 indicates success and non-zero indicates failure:
# echoes "command succeeded" because echo rarely fails: if /bin/echo hi; then echo 'echo'command succeeded'; else echo 'command failed'; fi # echoes "command failed" because rmdir requires an argument if /bin/rmdir; then echo 'command succeeded'; else echo 'command failed'; fi If you are using bash (and not sh)However, you can use [[ condition ]]all of the above examples only test against the program's exit status, which behaves more predictably when there are spaces or other special characters in your condition. Otherwise it isand ignore the sameprogram's output.
For find, I think you will need to test if any output was generated. -n tests for a non-empty string:
if [[ -n $(find /var/log/crashes -name "app-*.log" -mmin -5) ]] then service myapp restart fi A full list of test arguments is available by invoking help test at the bash commandline.
If you are using bash (and not sh), you can use [[ condition ]], which behaves more predictably when there are spaces or other special cases in your condition. Otherwise it is generally the same as using [ condition ]. I've used [[ condition ]] in this example, as I do whenever possible.
I also changed `command` to $(command), which also generally behaves similarly, but is nicer with nested commands.