exit command: Exit the Shell
exit command Function Description
Use the exit command to exit the Shell.
Executing exit causes the shell to exit with the specified status value. If no parameter is set, the shell exits with the return value of the last command as the return value of exit.
exit command Syntax
exit [Option n]
-
Option: The specified shell return value (integer).
-
The return value is the value of the parameter n you specify. If you specify a parameter greater than 255 or less than 0, the return value will always be between 0 and 255 by adding or subtracting 256.
exit command demo
Exit the Shell.
[root@deepinout ~]# exit
logout
You can also use ctrl+d
to exit the current terminal, and the following lists the ways to turn this feature on or off.
# Open ctrl+d to exit the terminal
set -o ignoreeof
# Close ctrl+d to exit the terminal
set +o ignoreeof
In the script, go to the directory where the script is located, otherwise exit.
cd (dirname0) || exit 1
In the script, determine the number of parameters, print the usage method if it doesn’t match, and exit:
if [ "#" -ne "2" ]; then echo "usage:0 <area> <hours>" exit 2fi
In the script, delete temporary files on exit.
trap "rm -f tmpfile; echo Bye." EXIT
Check the exit code of the previous command.
./mycommand.shEXCODE=?if [ "EXCODE" == "0" ]; then echo "O.K"fi
This command is built-in to bash, see the
help
command for help information.