我使用set -e到的第一个错误停止bash脚本。
一切正常,除非我使用命令&&:
$ 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
$
Run Code Online (Sandbox Code Playgroud)
和....相比:
$ 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
$
Run Code Online (Sandbox Code Playgroud)
第一个例子仍然 echo I'm running!,但第二个没有。为什么他们的行为不同?
更新。类似问题:https : //stackoverflow.com/questions/6930295/set-e-and-short-tests