#错误类型是专属的退出码:取值 3 到 125,
#名字要能说明其含义
readonly errEmptyName=3
checkName() {
if [[ -z $1 ]]; then
echo "Oops! The name is empty" >&2
return "$errEmptyName"
fi
}
#set -e 在第一个失败的命令处结束 shell,
#就像无人捕获的异常;用 ( ) 可让脚本继续运行
(
set -e
checkName ""
echo "not printed"
) 2> /dev/null
code=$?
#code is 3
#bash 有自己约定的退出码:127 表示找不到命令,
#126 表示文件不可执行,128 + n 表示被信号 n 终止
noSuchCommand 2> /dev/null
notFound=$?
#notFound is 127
echo "code is $code"
echo "notFound is $notFound"