What is the right way in bash
to do the following:
[ -x /path/to/file ] || multiple_actions
where multiple_actions
include e.g. printing some message and exit 1
I tried to do it as:
[ -x /path/to/file ] || echo Can't execute file; exit 1
It works, however I'm not sure if this the right way to do so? May be there are some potential hidden errors?
CodePudding user response:
What you tried does not do what you want. It always exits with status 1. Either use an if
command:
if ! [ -x ... ]; then this; that; fi
or a {}
compound command:
[ -x ... ] || { this; that; }