I have the following bash script. I set errexit (set -e) and am expecting the function to exit after the bad cd
command.
#!/bin/bash
set -e
wtf() {
cd non_existent_directory
echo "SHOULD EXIT BEFORE THIS PRINTS"
}
wtf || echo "WORKED AS EXEPECTED"
But sadly it doesn't:
$ ./wtf.sh
./wtf.sh: line 6: cd: non_existent_directory: No such file or directory
SHOULD EXIT BEFORE THIS PRINTS
How can I make it exit before that echo? I looked at the -e
option here :http://www.tldp.org/LDP/abs/html/options.html
and can't see why this wouldn't work?