Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output return code in shell?

Tags:

linux

bash

shell

sh

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?

like image 944
yegor256 Avatar asked Jul 24 '11 22:07

yegor256


People also ask

How do I return in shell?

return command is used to exit from a shell function. It takes a parameter [N], if N is mentioned then it returns [N] and if N is not mentioned then it returns the status of the last command executed within the function or script.

What is return code in shell script?

Most shell commands issue return codes that show whether the command executed properly. By convention, if the value returned is 0 (zero), then the command executed properly; any other value shows that it did not.

Can we return a value from shell script?

You can do three things: Echo a string. Return an exit status, which is a number, not a string. Share a variable.


1 Answers

echo $? >> /path/to/return_code 

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

like image 82
jman Avatar answered Oct 11 '22 18:10

jman