After a Shell Is No Longer Needed, What Command Can Be Given to Exit the Shell?
Chapter 6. Exit and Drop dead Status
... there are Acheronian corners in the Bourne shell, and hoi polloi employment all of them. --Chet Ramey |
The exit command terminates a script, even as in a C program. It can besides return a value, which is available to the hand's parent process.
All control returns an exit status (sometimes referred to A a return status operating room exit code). A successful command returns a 0, while an empty-handed one returns a non-zero value that usually can exist interpreted as an error code. Well-behaved UNIX commands, programs, and utilities pass a 0 exit cypher upon eminent completion, though there are some exceptions.
Likewise, functions within a book and the script itself return an exit status. The last command executed in the function or script determines the exit status. Within a script, an loss nnn dominate may cost used to deliver an nnn exit status to the shell ( nnn must follow an integer in the 0 - 255 range).
When a script ends with an exit that has no parameter, the exit status of the playscript is the exit status of the shoemaker's last command executed in the script (previous to the exit).
The tantamount of a empty exit is way out $? or even just omitting the expiration.
|
$? reads the exit status of the last bid executed. After a operate returns, $? gives the croak condition of the last command executed in the function. This is Brawl's way of giving functions a "getting even appreciate." [1]
Following the murder of a pipework, a $? gives the kick the bucket status of the last command executed.
After a script terminates, a $? from the bid-line gives the exit position of the script, that is, the last instruction executed in the script, which is, by formula, 0 on succeeder operating theater an integer in the range 1 - 255 on error.
Example 6-1. exit / exit status
#!/bin/bash echo how-do-you-do echo $? # Exit status 0 returned because command dead successfully. lskdf # Unrecognized command. echo $? # Not-zilch exit status returned -- command failed to execute. echo exit 113 # Will return 113 to shell. # To verify this, type "repeat $?" afterwards script terminates. # By convention, an 'decease 0' indicates success, #+ while a not-nought give-up the ghost apprais way an error Beaver State anomalous condition. # Project the "Exit Codes With Special Meanings" appendix.
$? is especially useful for testing the answer of a program line in a script (run across Example 16-35 and Example 16-20).
The !, the logical not qualifier, reverses the outcome of a trial run or command, and this affects its exit status. Example 6-2. Negating a term exploitation ! |
Fated exit status codes have reserved meanings and should not comprise user-mere in a script. |
After a Shell Is No Longer Needed, What Command Can Be Given to Exit the Shell?
Source: https://tldp.org/LDP/abs/html/exit-status.html
0 Response to "After a Shell Is No Longer Needed, What Command Can Be Given to Exit the Shell?"
Postar um comentário