October 2001
Beginner
1024 pages
25h 8m
English
Most programs in FreeBSD return an exit status when they terminate. The exit status is usually 0 if successful, and some number other than 0 if something went wrong. Some programs will return a different exit status, depending on the problem. Often, this information can be found in the program's man page.
The exit status of the last program that ran is stored in the magic variable “$?”. Here are a couple of examples:
bash$ ls > /dev/null bash$ echo $? 0 bash$ bash$ ls -2 /dev/null ls: illegal option -- 2 usage: ls [-ABCFGHLPRTWabcdfgiklnoqrstu1] [file ...] bash$ echo $? 1 bash$
The first example will set the magic variable $? to 0, as shown (output of the ls command was redirected to /dev/null for brevity in the example). The second ...
Read now
Unlock full access