exit

Cause the shell to exit and save history.

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.

Example

$ exit
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

“An exit strategy is a means of escaping one's current situation, typically an unfavourable situation” - Wikipedia

Related macOS commands:

logout - Exit a login shell.
return - Exit a shell function.
shell_session_delete_expired - Delete expired sessions when "You have exceeded the maximum number of shell sessions".
shell_session_save - Save shell sessions.
shell_session_update - updated saved session.
screen - Multiplex terminal, run remote shells via ssh.
shutdown - Shutdown or restart macOS.


 
Copyright © 1999-2020 SS64.com
Some rights reserved