本文介绍了Bash获取命令的返回值并使用此值退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想执行一个命令,然后获取该命令的返回值.完成后,我想退出并给退出我之前执行的命令的返回值.我已经有这段代码,但是似乎没有用.
I want to execute a command then get the return value of this command.when it's done i want to exit and give exit the return value of the previous command, the one i just executed. I already have this piece of code but it doesn't seem to work.
exec gosu user /var/www/bin/phpunit -c app
typeset ret_code
ret_code=$?
if [ $ret_code == 0 ]; then
exit 0
fi
exit 1
我该怎么办?谢谢
推荐答案
我认为您的问题是 typeset
本身创建的返回值为0.请尝试
I think your problem is that typeset
itself creates a return value of 0. Try
gosu user /var/www/bin/phpunit -c app
ret_code=$?
return $ret_code
这篇关于Bash获取命令的返回值并使用此值退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!