44.7 Exit Status of UNIX ProcessesWhen a UNIX process (command) runs, it can return a numeric status value to the process that called (started) it. The status can tell the calling process whether the command succeeded or failed. Many (but not all) UNIX commands return a status of zero if everything was okay or non-zero (1, 2, etc.) if something went wrong. A few commands, like grep and diff , return a different non-zero status for different kinds of problems; see your online manual pages to find out.
The Bourne shell puts the exit status of the previous command in the
question mark (
$ In the C shell, use the status variable instead:
% Of course, you usually don't have to display the exit status in this way, because there are several ways ( 44.8 , 44.9 , 44.10 ) to use the exit status of one command as a condition of further execution.
The exit status of pipelines ( 1.4 ) is the status of the last command in the pipeline. [2] You can't test the exit status of a background job in the Bourne shell unless you use the wait command to wait for it (in effect, to bring the job out of the background).
- |
|