考虑以下:
#!/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并终止脚本?