Commands (including the scripts and shell functions we write) issue a value to the system when they terminate, called an exit status. This value, which is an integer in the range of 0 to 255, indicates the success or failure of the command’s execution. By convention, a value of 0 indicates success, and any other value indicates failure. The shell provides a parameter that we can use to examine the exit status. Here we see it in action:
ls -d /usr/bin/usr/bin [me@linuxbox ˜]$
echo $?0 [me@linuxbox ˜]$
ls -d /bin/usrls: cannot access /bin/usr: No such file or directory [me@linuxbox ˜]$
In this example, we execute the
ls command twice. The first time, the command executes successfully. If we display the value ...