我在脚本中有这个条件:
if [[ "${SUMAN_ENV}" != "local" ]]; then
./suman.sh $@ # run this script instead
# need to exit here
fi
Run Code Online (Sandbox Code Playgroud)
如果满足条件,我想运行另一个脚本。
这样做的最佳方法是这样做:
if [[ "${SUMAN_ENV}" != "local" ]]; then
./suman.sh $@
exit $? # exit with the code given by the above command
fi
Run Code Online (Sandbox Code Playgroud)
或者有其他方法吗?
小智 12
文件hello:
#!/bin/sh
echo "$0"
exec ./world
echo "$0"
Run Code Online (Sandbox Code Playgroud)
文件world:
#!/bin/sh
echo "$0"
exit 33 # to have an exit code example
Run Code Online (Sandbox Code Playgroud)
运行hello:
$ ./hello
./hello
./world
$ echo $?
33
Run Code Online (Sandbox Code Playgroud)
在hello运行world通过exec并world完成后,其余部分hello不执行。退出代码是world.
| 归档时间: |
|
| 查看次数: |
2240 次 |
| 最近记录: |