44.11 Set Exit Status of a Shell (Script)Most standard UNIX commands return a status ( 44.7 ) . Your shell script should, too. This section shows how to set the right exit status for both normal exits and error exits. To end a shell script and set its exit status, use the exit command. Give exit the exit status that your script should have. If it has no explicit status, it will exit with the status of the last command run. Here's an example: a rewrite of the bkedit script from article 44.8 . If the script can make a backup copy, the editor is run and the script returns the exit status from vi (usually 0). If something goes wrong with the copy, the script prints an error and returns an exit status of 1. Here's the script:
Here's what happens if I run it without a filename:
$ And here's what's left in the exit status variable:
$ - |
|