我在脚本中设置了
set -e
然后我在所述脚本的 if 语句中运行命令:
if adb -s emulator-5554 uninstall my.package ; then
echo "handle emulator command return code here ... "
fi
我想获取命令emulator-5554 uninstall my.package
的返回码,并根据其值处理返回码;我无法执行此操作,因为该命令嵌入在 if 语句中。
最佳答案
在 if
语句中不会影响您获取返回码的方式,并且 set -e
不适用于条件命令:
if adb -s emulator-5554 uninstall my.package ; then
echo "The command succeeded, yay!"
else
code="$?"
echo "The command failed with exit code $code"
fi
关于linux - 如何在 `set -e` 时有选择地处理非零退出代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56009935/