Changes

Jump to navigation Jump to search
Line 27: Line 27:  
To see exit status of the script, enter (see [[the exit status of a command]] for more information about special  shell variable $?) :
 
To see exit status of the script, enter (see [[the exit status of a command]] for more information about special  shell variable $?) :
 
<syntaxhighlight lang="bash" >echo $?</syntaxhighlight>
 
<syntaxhighlight lang="bash" >echo $?</syntaxhighlight>
 +
===Exit status at the CLI===
 +
Exit status is not limited to shell script. Every time command terminated shell gets an exit code indicating success or failure of the command. Hence we can use the particular bash variable $? to get the exit status of the command. For instance:
 +
<syntaxhighlight lang="bash" >ping -q -c 4 www.cyberciti.biz >/dev/null
 +
echo $?</syntaxhighlight>
 +
Output:
 +
<pre>0</pre>
 +
In this example, we will see the exit status of the last command (command3) only:
 +
<syntaxhighlight lang="bash" >command1 | command2 | command3
 +
## will get the exit status of the last command in the pipeline ##
 +
echo $?</syntaxhighlight>
 +
 
==Shell script example==
 
==Shell script example==
 
* Any non zero value indicates unsuccessful shell script termination.  
 
* Any non zero value indicates unsuccessful shell script termination.  

Navigation menu