How Do I Find the Return Code in Unix?
Contents

To get the exit code of a command type echo $? at the command prompt. In the following example a file is printed to the terminal using the cat command.

How do I find my Linux return code?

To check the exit code we can simply print the $? special variable in bash. This variable will print the exit code of the last run command. As you can see after running the ./tmp.sh command the exit code was 0 which indicates success, even though the touch command failed.

What is return code in shell script?

Exit codes are a number between 0 and 255, which is returned by any Unix command when it returns control to its parent process. … These can be used within a shell script to change the flow of execution depending on the success or failure of commands executed.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest