How to find the exit code of the last executed command on bash using "?" environment variable

view full story

http://linuxers.org – TweetEvery command or program returns an exit code to convey the execution status - success or failure. In Linux, programs return zero in case of success and a non-zero value in case of an error. If you want to find out the return value/exit status of the last executed command on bash, you can use the “?” environment variable. Here is an example. [shredder12]$ exit 0 [shredder12]$ echo $? 0 [shredder12]$ exit 4 [shredder12]$ echo $? 4 Here we are directly using the exit command to return the status. We can use a different scenario too. [shredder12]$ ls [shredder12]$ echo $? 0 [ (General)