我在脚本中有这个条件:
if [[ "${SUMAN_ENV}" != "local" ]]; then
./suman.sh $@ # run this script instead
# need to exit here
fi
如果满足条件,我想运行另一个脚本。
最好的方法就是这样做:
if [[ "${SUMAN_ENV}" != "local" ]]; then
./suman.sh $@
exit $? # exit with the code given by the above command
fi
或者还有其他方法吗?
答案1
文件hello
:
#!/bin/sh
echo "$0"
exec ./world
echo "$0"
文件world
:
#!/bin/sh
echo "$0"
exit 33 # to have an exit code example
跑步hello
:
$ ./hello
./hello
./world
$ echo $?
33
hello
运行world
viaexec
并完成后world
,其余部分hello
不执行。退出代码是 之一world
。