exit

Exit from a program, shell or log out of a Unix network.

Syntax
      exit [n]

Key
   n   Set the exit status to n (default=0)

If n is omitted, the exit status is that of the last command executed. A trap on EXIT is executed before the shell terminates.

The exit status code can be displayed with echo $?

The shell variable SHLVL displays how deeply nested you are in the bash shell, the first session opened in a terminal will be 1 and each subsequent shell session opened will increment the number. If SHLVL is greater than 1 then exit will exit the shell, if SHLVL is = 1, then exit will logout and close the terminal.

In a subshell SHLVL does not increment, but instead you can compare $BASHPID to $$

exit is a bash built in command.

"Either he's dead or my watch has stopped!" ~ Groucho Marx (A Day at the Races)

Related linux commands:

logout - Exit a login shell.
lo, bye, quit
<ctrl><d> - End of File.
return - Exit a shell function.
shutdown - Shutdown or restart linux.
Equivalent Windows commands: EXIT.


 
Copyright © 1999-2020 SS64.com
Some rights reserved