Linux exit commandLinux exit command is used to exit from the current shell. It takes a parameter as a number and exits the shell with a return of status number. If we did not provide any parameter, it would return the status of the last executed command. The exit command closes a script and exits the shell. If we have more than one shell tab, the exit command will close the tab where it is executed. This is a built-in command, and we cannot find a dedicated manual page for this. Syntax:From the above command, after pressing the ENTER key, the terminal will be closed, and all the normal running processes of the terminal will be ended. The exit command is the most useful common in Linux. We can pass with it many times. It uses the exit() function to terminate the normal process. Some points regarding the exit command are as following:
Options:The exit command does not provide many options. But, it supports the following options:
If we execute it without any parameter, it simply closes the terminal. Execute it as follows: The above command will simply close the terminal.
If we pass a parameter, it will close and return the same exit status. For example, if we execute it with an exit status 10, it will return a status of 10. consider the below command: The above command will close the terminal and return a status of 10. The return statuses are useful as some times they can be tracked to tell error. For example, the return status '0' means the program has successfully executed, and '1' means the program has minor errors.
To display the exit status of the last executed command, execute the "echo $?" command as follows: The above command will display the last returned status. Consider the below output:
Let's create a script, 'Demo.sh.' To create it, execute the following command: Save the above script by pressing the CTRL+D keys. Now, execute the script by executing the following commands: The above command will execute the script. Now, check the exit status of the script by executing the below command: Consider the below output: As from the above output, we can see that the exit status of the given script is 0, which means it is successfully executed. Getting HelpThe exit command is a built-in utility. There are no dedicated manual pages available for it. However, it supports the "-help" option, which displays information about the command. To get help, execute the command as follows: The above command will display help on the command line. We can also execute the help exit command as follows: Both commands will produce the same output. Consider the below output: Next TopicLinux File Hierarchy |