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?
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.
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.
You can do three things: Echo a string. Return an exit status, which is a number, not a string. Share a variable.
echo $? >> /path/to/return_code
$? has the return code of the last statement in bash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With