1. Linux Command exit-description of the purpose of exiting the Current Shell
The exit command is used to exit the current shell. In the shell script, you can terminate the execution of the current script. If you do not exit, you may continue to execute subsequent programs.
Common Parameters
Format: Exit n
Exit. Set exit code to n. (Cause the shell to exit with a status of n .)
Format: Exit
Exit. The exit code is the exit code of the last command. (If n is omitted, the exit status is that oftheLastCommand executed .)
Format: $?
The exit code of the previous command.
Format: Trap "commands" Exit
Execute the command specified by commands when exiting. (A trap on exit is executed before the shellterminates .)
Exit code (exit status, or exit code) Conventions:
0 indicates success (zero-success)
Non-0 indicates failure (non-zero-Failure)
2 indicates improper usage (incorrect usage)
127 indicates that the command is not found (command not found)
126 indicates that it is not executable (not an executable)
> = 128 signal generation
When you exit 0, you call the environment echo $? 0 is returned, that is, the calling Environment considers that your program is correctly executed.
When you exit 1, it is generally an error that defines this 1, or it can be another number. Many system programs have this error number as agreed. If the value is not 0, the program runs incorrectly. The call environment can determine whether the program runs OK Based on the returned value.
If you use script a to call script B, you must identify whether B returns normally in script a Based on exit 0 or 1.
After executing B, Judge $? Is the return value
Example
Example 1 exit the Current Shell
[root@new55 ~]# [root@new55 ~]# exit logout
Example 2 in the script, enter the directory where the script is located; otherwise, exit
Bash code
cd $(dirname $0) || exit 1
Example 3: In the script, determine the number of parameters. If the number does not match, print the usage mode and exit.
Bash code"Exit 2 fi" Quality = "high" allowScriptAccess = "always" type = "application/X-Shockwave-flash" pluginspage = "http://www.macromedia.com/go/getflashplayer">
if [ "$#" -ne "2" ]; then
echo "usage: $0 <area>
exit 2
fi
Example 4: delete a temporary file when exiting the script
Bash code
trap "rm -f tmpfile; echo Bye." EXIT
Example 5 check the exit code of the previous command
Bash code
./mycommand.sh
EXCODE=$?
if [ "$EXCODE" == "0" ]; then
echo "O.K"
fi
2. expr command
Arithmetic Operations on Integer Variables
Expr 3 + 5
Space
Expr $ var1-5
Expr $ var1/$ var2 Division
Expr $ var1 \ * 10 multiplication escape characters