是否有可能得到一个子shell退出code? [英] Is it possible to get the exit code from a subshell?

查看:133
本文介绍了是否有可能得到一个子shell退出code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们想象我有一个bash脚本,在这里我称之为:

Let's imagine I have a bash script, where I call this:

bash -c "some_command"
do something with code of some_command here

是否有可能获得 some_command 的code?我不执行 some_command 直接运行该脚本,因为我不想改变它的环境的外壳。

Is it possible to obtain the code of some_command? I'm not executing some_command directly in the shell running the script because I don't want to alter it's environment.

推荐答案

$?将包含返回code some_command 只是像往常一样。

$? will contain the return code of some_command just as usual.

当然,它也可能包含来自一个bash的code,万一出事了之前您的命令,甚至可以执行(错名,诸如此类的东西)。

Of course it might also contain a code from bash, in case something went wrong before your command could even be executed (wrong filename, whatnot).

这篇关于是否有可能得到一个子shell退出code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆