1 #!/bin/sh -e
2
3 cat /etc/ppppp
4 echo ppppppp
首先明确#!/bin/sh -e这些完全可以没有,此时调用默认解释器,默认选项生成子shell执行脚本,此定义唯一有用的是./file.sh执行的时候,sh file.sh也完全忽略#!/bin/sh -e.
sh -e 执行脚本明确遇到命令非0的exit code,整个脚本立即退出,默认关闭
为了灵活可以set设置环境变量,来看一下set -e的解释
set -e Exit immediately if a command exits with a non-zero status
等同于set -o errexit
set -e
commands
set +e
这样commands代码段,如发生错误脚本会立即退出
有时候也可以sh -e file.sh来执行脚本
原文:https://www.cnblogs.com/dissipate/p/12993954.html