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.
$ exit logout Saving session... ...copying shared history... ...saving history...truncating history files... ...completed. [Process completed]
“I think my relationship with social media has changed so much that I really resent social media now. And I'm trying to figure out what a successful exit strategy is as someone who has gotten a lot of opportunities because of social media and how it's given me a portfolio” ~ Patti Harrison
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.