小编Roa*_*owl的帖子

不存在的文件上的 Shell 脚本源终止脚本

考虑以下:

#!/bin/sh

# GNU bash, version 4.1.2(1)-release
echo "Start"
cd /path/does/not/exists # this does not terminate
source /path/does/not/exists

echo $?
echo "End"
Run Code Online (Sandbox Code Playgroud)

结果:

Start
./test.sh: line 6: /path/does/not/exists: No such file or directory
Run Code Online (Sandbox Code Playgroud)

为什么echos都不打印任何内容并且脚本终止?为什么只source捕获错误而不设置显式set -e并终止脚本?

bash shell posix sh

2
推荐指数
1
解决办法
34
查看次数

标签 统计

bash ×1

posix ×1

sh ×1

shell ×1