1、set -e
执行的时候如果出现了返回值为非零,整个脚本就会立即退出。
2、set +e
执行的时候如果出现了返回值为非零将会继续执行下面的脚本。
3、set -o pipefail
set -e 有一个例外情况,就是不适用于管道命令。
所谓管道命令,就是多个子命令通过管道运算符(|)组合成为一个大的命令。Bash 会把最后一个子命令的返回值,作为整个命令的返回值。也就是说,只要最后一个子命令不失败,管道命令总是会执行成功,因此它后面命令依然会执行,set -e 就失效了。set -o pipefail 用来解决这种情况,只要一个子命令失败,整个管道命令就失败,脚本就会终止执行。
本文参考自:
(1)http://www.ruanyifeng.com/blog/2017/11/bash-set.html?utm_source=tool.lu
(2)https://www.runoob.com/linux/linux-comm-set.html