如何在shell中输出返回码? [英] How to output return code in shell?

查看:77
本文介绍了如何在shell中输出返回码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 sh 调用自定义外壳程序脚本:

I'm trying to call a custom shell script through sh:

/bin/sh -c 'myscript.sh` >log.txt 2>&1 & echo $!

此命令的输出是已创建的后台进程的PID.我想指示/bin/sh myscript.sh 的返回码保存到某个文件中.有可能吗?

Output of this command is a PID of a created background process. I want to instruct /bin/sh to save return code of myscript.sh to some file. Is it possible?

推荐答案

(/bin/sh -c "myscript.sh" >log.txt 2>&1 ; echo $? >somefile) & echo $!

这篇关于如何在shell中输出返回码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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