假设我编写了如下代码:
if [ ${?} -ne 0 ]; then
exit ${?}
这能正常工作吗? 这是正确的“语法方面”吗?
最佳答案
if
语句中的 [
命令将在检查后设置 $?
。您需要在测试前保存原始退出状态。
some_command
es=$?
if [ "$es" -ne 0 ]; then
exit "$es"
fi
关于bash - 在 bash 中使用 "exit ${?}"是否正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60637423/