Skip to main content
5 of 7
Add link to a similar question

Bash script with `set -e` doesn't stop on `... && ...` command

I use set -e to stop bash script on first error.

All work OK unless I use command with &&:

$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
I'm running! =P
$ cat script
set -e
cd not_existing_dir && echo 123
echo "I'm running! =P"

compared with:

$ ./script
./script: line 2: cd: not_existing_dir: No such file or directory
$ cat script
set -e
cd not_existing_dir
echo "I'm running! =P"

The first example still echoes I'm running!, but the second one doesn't. Why do they behave differently?

UPD. Similar question: http://stackoverflow.com/questions/6930295/set-e-and-short-tests