By: Vivek G. Emailed: 1785 times Printed: 2624 times
By default in Linux if particular command/shell script is executed, it return two type of values which is used to see whether command or shell script executed is successful or not.
(1) If return value is
zero (0), command is
(2) If return value is nonzero, command is not successful or some sort of error executing command/shell script.
This value is know as Exit Status.
But how to find out exit status of command or shell script?
Simple, to determine this exit Status you can use $? special variable of shell.
For e.g. (This example assumes that unknow1file doest
not exist on your hard drive)
$ rm unknow1file
It will show error as follows
rm: cannot remove `unkowm1file': No such file or directory
and after that if you give command
$ echo $?
it will print nonzero value to indicate error. Now give command
$ echo $?
It will print 0 to indicate command is successful.
Most Viewed Articles (in Linux )
Latest Articles (in Linux)
Comment on this tutorial
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews