Home Tutorials IT Jobs Source Codes Certifications Discussion Forum
  Linux Tutorial
Linux Introduction
Unix
Linus and Linux
What Kernel Is?
Linux Commands
Linux Shell
Root and Other Users
Virtual Consoles
Logoff and Shutdown
The Command Prompt
Wildcards
Command History
Aliases
Redirection
Pipelines
Stopping a Program
Environment Variables
Exit Status
Linux File System
Linux File Names
Linux Directories
Directory Terminology
Navigating the File System
Listing Linux Files
Linux Downloads
Recommended Books
   IT Jobs
Software Jobs
Networking Jobs
   Model Question Papers
BE Computer Science
MCA
BCA
Others
 
   

Exit Status

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 successful.
(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
$ ls
$ echo $? 
It will print 0 to indicate command is successful.

Exercise

Try the following commands and not down the exit status:
$ expr 1 + 3
$ echo $?

$ echo Welcome
$ echo $
?

$ wildwest canwork?
$ echo $?

$ date
$ echo $?

$ echon $?
$ echo $?

<< Previous | Next >>

Home  |  About us  | Privacy  |  Disclaimer  |  Contact us |  Advertise with us | Our Link Partners
All Rights Reserved 2009, CodeTeller.com