Quote:
Originally Posted by hazel
OK. "&&" and "||" are boolean operators, aren't they? So how does that work if the exit codes from test and rm are just integers?
|
Slightly off-topic, but I have seen cases where some shells (Including bash) will just silently exit when using "&&" in some circumstances. It seems to be more common when using "set -e" and at the end of nested loops/conditionals (Adding a "echo" or another command at the end sometimes helps) and when used many times consecutively. On the other hand "||" doesn't seem to suffer from these problems nor does using more canonical test statements.
This can workaround it where the ":" is a no-op.
Code:
{ [ "${foo}" ] && bar; } || :
Or this.
Code:
[ -z "${foo}" ] || bar
I have also not yet seen some shells like dash or mksh suffer from these problems.