4 ms·
Original article: >The echo command always exists [sic] with 0, so this propagates to exit if the first expression is truthful. (emphasis his) In both bash an
by cb321 6y ago
Original article:
>The echo command always exists [sic] with 0, so this propagates to exit if the first expression is truthful. (emphasis his)
In both bash and dash (and probably most), echo will fail if there is no stdout. E.g.:
j.sh:
echo hello && exit 2
$ bash j.sh >&-
j.sh: line 1: echo: write error: Bad file descriptor
$ echo $?
1
Note the exit value ($?) is 1, not 2.
EDIT: Also note that not exiting the script could cause a flurry of cascading errors (likely permission errors in the article's example).