The Linux Newbie Guide  ⇒    Fundamentals     Advanced     Supplement   Command Index   ENG⇒中
All rights reserved, please indicate the source when citing
  

exit Command to Exit the Current Shell






The exit command is used to terminate the current shell. It is a built-in command, so it is available in all types of shells, such as Bash, Zsh, C shell, and more.

The basic syntax of the exit command is as follows:
exit [N].


Here, "N" is an integer. The default return value is 0, indicating a successful shell exit. For example, executing exit 0 signifies a successful exit.

The exit command can also be used to exit from a subshell. For instance, the following commands create a subshell, execute the cp command within it, and then return to the parent shell:

Example:
bash
cp -r folder1/ folder2/
exit 
echo $0 ← Check the return value of the previous command

For examples and usage, refer to the provided link.