How to output return code in shell?

点点圈 提交于 2020-02-18 06:03:13

问题


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

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

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?


回答1:


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



回答2:


echo $? >> /path/to/return_code

$? has the return code of the last statement in bash.




回答3:


(
/bin/sh -c 'myscript.sh` >log.txt 2>&1
echo $? > some_file
) &


来源:https://stackoverflow.com/questions/6810279/how-to-output-return-code-in-shell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!