1. Intruduction
ExitmakeShell(script) to exit with a specified status value, Execute without parametersExitwhen, Shellor the script exits with the status value of the last execution command. Shellbefore exiting, Trapcan huntEXITsignal. 0indicates successful execution,Non-0The value table failed to execute. It is often used to determine the flow of statements and loop statements to control procedures and expressions.
exit allows you to set the state value at exit when scripting, using $? reference, a particular exit status value typically defines a specific exit meaning. You can also use test to check the exit status of an expression.
bash all < Span style= "font-family: ' New song body ';" The command returns the status 0 0 < Span style= "font-family: ' New song body ';" > so they can be used for conditional commands and commands List in
Exit Status Exit Status
When you exit a function, program, or command, an integer is returned to the parent command, which is called the exit state. exit, $? reference its value
judgment statements and loop statements are also used exit Span style= "FONT-FAMILY:CALIBRI;" > status built-in commands to control the process flow Span style= "font-family: ' The song Body '; > used to return a status $? status with 0 ~ 255
POSIX Several exit statuses as specified
Exit status |
|
0 |
Run successfully |
1 ~ the |
Various run failures |
126 |
The command was found but could not be executed |
127 |
Run command not found |
>128 |
The command was forcibly ended by the system. |
2. Sysopsis
Exit [Status value]
Status Value 0~255 value saved in? Variables in
3. Eg
Exit exit Shell, do not change $? the value
Exit 1 exits the shell and returns 1
4. Compare return
Exit is a system call that ends a process at any time while the program is running, deletes the memory space occupied by the process, and returns the status to the parent process, which typically used to identify some running information for a program.
return status exit from function. return without parameters, The return value of the last command in the function body is returned.
return Way (child ) returns when the script is executed, or it can return the specified status or the last command in the script exit Status.
return not used for function body, nor with . ( SOURCE) , an error occurs when the script is executed.
return will trigger Trap
so the correct usage is toreturn is used for function returns, exit for process exit. For example, if the main function calls a sub-function, using return in the child function returns to the main function, but the exit is mistakenly used in the child function will exit the process directly.
This article is from the "Adelphos" blog, make sure to keep this source http://adelphos.blog.51cto.com/2363901/1636235
Exit-shell exit Status