Linux exit command - Exit the Shell

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.

Like(1)
Linux Login Logout Command
Linux login commandLinux logout commandLinux nologin commandLinux exit commandLinux sulogin commandLinux rlogin commandLinux poweroff commandLinux ctrlaltdel CommandLinux shutdown commandLinux halt commandLinux reboot commandLinux init commandLinux runlevel commandLinux telinit command
Linux File Management Command
Linux cat commandLinux tac commandLinux nl commandLinux more commandLinux less commandLinux head commandLinux tail commandLinux rev commandLinux fold commandLinux fmt commandLinux expand commandLinux pr commandLinux sort commandLinux uniq commandLinux cut commandLinux comm commandLinux diff commandLinux join commandLinux diff3 commandLinux cmp commandLinux colrm commandLinux paste commandLinux mkdir commandLinux tr commandLinux split commandLinux csplit commandLinux tee commandLinux unexpand commandLinux patch commandLinux awk commandLinux sed commandLinux od commandLinux pwd commandLinux cd commandLinux ls commandLinux dir commandLinux dirs commandLinux touch commandLinux rmdir commandLinux cp commandLinux mv commandLinux rm commandLinux install commandLinux tmpwatch commandLinux file commandLinux du commandLinux wc commandLinux tree commandLinux cksum commandLinux md5sum commandLinux sum commandLinux dirname commandLinux mkfifo Command
Cron Expressions
Cron Expression to Run Every Day at 12 PMUnderstanding Vue Cron ExpressionsUnderstanding JS Cron ExpressionsA Comprehensive Guide to Cron Expressions for Scheduled TasksUnderstanding Linux Cron ExpressionsUnderstanding Quartz Cron ExpressionsCron ExpressionCron Time ExpressionCron Expression ParsingCron Expression: Executing a Task Every SecondCron Expression for Every Minute ExecutionCron Expression to Execute Every 10 MinutesCron Expression: Executing Every HourCron Expression to Execute Once a YearCron Expression: How to Schedule a Task to Run Daily at Midnight?