如何在Bash脚本中捕获退出代码 [英] How to trap exit code in Bash script
本文介绍了如何在Bash脚本中捕获退出代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的bash代码中有很多出口点.我需要在退出时进行一些清理工作,因此我使用了陷阱为退出添加了回调,如下所示:
There're many exit points in my bash code. I need to do some clean up work on exit, so I used trap to add a callback for exit like this:
trap "mycleanup" EXIT
问题是退出代码不同,我需要做相应的清理工作.我可以在mycleanup中获得退出代码吗?
The problem is there're different exit codes, I need to do corresponding cleanup works. Can I get exit code in mycleanup?
推荐答案
我认为您可以使用$?
获取退出代码.
I think you can use $?
to get the exit code.
这篇关于如何在Bash脚本中捕获退出代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文