【发布时间】:2018-05-13 10:04:13
【问题描述】:
我必须在 shell 脚本中使用 exec 运行命令,并且我需要捕获退出代码以防出错并运行另一个命令,例如
#!/bin/sh
set +e
exec command_that_will_fail
if [ $? -eq 1 ]; then
echo "command failed, running another command"
fi
我知道 exec 替换了当前的 shell 并继续,我的问题是如果 exec 不成功,我需要运行另一个命令。
【问题讨论】:
标签: shell error-handling exec