How Do I Find Exit Code in Linux?

How Do I Find Exit Code in Linux?
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. The command was successful.

How do you show exit code in Linux?

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.

How do I find the process exit code?

Get exit code of a background process

  1. Run the command CMD in parallel as a background process ( CMD & ).
  2. In the main script, have a loop to monitor the spawned command every few seconds. …
  3. Exit the loop when the spawned command terminates.
  4. Capture and report the exit code of the spawned process.
James H. Sterling
Author

James H. Sterling

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