set -e 等同于 set -o errexit,当 shell 执行的时候,如果出现错误立即退出。
$ ls test.sh rivsidn@rivsidn:~/test$ cat test.sh #! /bin/bash set -e
touch aa
cp aa ./bb/
touch cc
所示,如果不加 set -e 时候,会生成两个文件 aa, cc; 如果加 set -e 只会生成 aa 一个文件。
https://blog.51cto.com/sf1314/2062713
原文:https://www.cnblogs.com/rivsidn/p/11019449.html