【发布时间】:2018-09-25 18:13:09
【问题描述】:
在 Bash 中,我想要一个基于运行命令的退出代码的 if 语句。例如:
#!/bin/bash
if [ ./success.sh ]; then
echo "First: success!"
else
echo "First: failure!"
fi
if [ ./failure.sh ]; then
echo "Second: success!"
else
echo "Second: failure!"
fi
success.sh
#!/bin/bash
exit 0
failure.sh
#!/bin/bash
exit 1
这应该打印出来:
First: success!
Second: failure!
我将如何实现这一目标?谢谢!
【问题讨论】:
-
您应该从您的帖子中删除 signals 标签。没有像 exit signal 这样的东西,您的帖子是关于 exit codes 的,而不是关于信号的。询问程序终止的信号也是一个有意义的问题,但这不是您要问的。
标签: bash shell process command exit-code