我有这个 Bash 脚本:
#!/bin/bash
set -x
function doSomething() {
callee
echo "It should not go to here!"
}
function callee() {
( echo "before" ) && (echo "This is callee" && exit 1 )
echo "why I can see this?"
}
doSomething
这是结果:
+ set -x
+ doSomething
+ callee
+ echo before
before
+ echo 'This is callee'
This is callee
+ exit 1
+ echo 'why I can see this?'
why I can see this?
+ echo 'It should not go to here!'
It should not go to here!
我看到了命令exit
,但它没有退出脚本——为什么不起作用exit
?