I use set -e to stop bash script on first error.
All work OK unless I use command with &&:
$ cat script
set -e
cd not_existing_dir && echo 123
echo "I'm running! =P"
$
$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
I'm running! =P
$
compared with:
$ cat script
set -e
cd not_existing_dir
echo "I'm running! =P"
$
$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
$
The first example still echoes I'm running!, but the second one doesn't. Why do they behave differently?
UPD. Similar question: https://stackoverflow.com/questions/6930295/set-e-and-short-tests
cdcommand – Aleksei Chernenkov Sep 27 '16 at 09:23set -ebehavior is surprising. – Charles Duffy Sep 27 '16 at 15:20set -eu -o pipefailspecificallypipefail. – Richard Tyler Miles Sep 18 '22 at 21:05pipefailwon't help. It works for pipes (|) and not for AND/OR – Aleksei Chernenkov Sep 20 '22 at 07:19