小编vca*_*llo的帖子

为什么 `source foo && true` 在 bash 中退出脚本?

所以,我读过这个: 带有 `set -e` 的 Bash 脚本不会在 `... && ...` 命令上停止

这说得通。那么现在问题来了:

测试A:

$ cat ./test.sh 

set -ex
source foo && true
echo 'running'

$ ./test.sh 
++ source foo
./test.sh: line 16: foo: No such file or directory

$ echo $?
1
Run Code Online (Sandbox Code Playgroud)

测试乙:

$ cat ./test.sh 

set -ex
cat foo && true
echo 'running'

$ ./test.sh 
++ cat foo
cat: foo: No such file or directory
++ echo running
running

$ echo $?
0
Run Code Online (Sandbox Code Playgroud)

为什么source唯一违反此规则(粗体)?

如果失败的命令是紧跟在 …

shell bash shell-script

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

标签 统计

bash ×1

shell ×1

shell-script ×1