4 ms·
Mainly, the reason why Bash's "set -e" doesn't do what you expected is this. set -e comes from the POSIX shell language, descended from the Bourne Shell. The
by kazinator 4y ago
Mainly, the reason why Bash's "set -e" doesn't do what you expected is this.
set -e comes from the POSIX shell language, descended from the Bourne Shell.
The examples you're using use obscure Bash features. For instance let turns an arithmetic result into a termination status, where 0 is fail (opposite to the POSIX convention and all).
set -e works to the extent that your commands have a sane termination status, which they generally do if they are standard built-ins or well-behaved utilities.
One Bash feature improves the effectiveness of set -e (or exit status testing in general). In a command pipe:
a | b | .. | z
the termination status is obtained from z. That's standard. If z indicates success, the pipeline is successful no matter how a through y terminate. Bash has a "pipefail" option to help with this.
- yread 4y agoTFA talks about pipefail and how it sometimes fails when command writes too much. Is read(1) an obscure feature now?