In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use the exit command in Shell. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Introduction:
Exit is used to exit the current shell environment process and can return a status code. Generally use $? You can get the status code.
Syntax:
The correct exit syntax exit # returns a status code of 0 by default, which generally means that the command is executed successfully
Error exit syntax exit non-zero numeric # the recommended range of numbers 0-255generally represents a command execution failure
Exit application scenario
1. End the current shell process
two。 When the shell process exits in error, different status values can be returned to represent different errors.
For example, when operating a file in a script file, you can return 1 to indicate that the file does not exist, 2 to indicate that the file does not have read permission, and 3 to indicate that the file type is incorrect.
Instance requirements:
Write a shell script to exit using exit, return a non-zero numeric status value when exiting, execute the script file and print the return status value
Steps:
1. Create an exit.sh file
two。 Edit the exit.sh file to end the current shell with exit digital exit
3. Execute file, print return status value
Demonstrate that vim exit.shalloxambinash binhecho 'hello'exit 2echo' word'# will only output helloecho $? # output 2 to get a summary of the status code returned by the last command execution.
Application scenarios of exit
End the current shell process
Different status codes can be returned for different business processes.
Attached: exit suffix digit function
The exit command is the same as exiting shell and returning the given value. You can terminate the current script execution in a shell script.
Execute exit to cause shell to exit with the specified status value. If the status value parameter is not set, shell exits with a preset value.
A status value of 0 indicates a successful execution, while other values indicate a failure.
0 system stop
1 single user system, no need to log in
2 multi-user system but does not support NFS, command line login
3 complete multi-user mode, command line login
4 unused
5x11 graphic mode, graphical mode login
6 restart the system
Thank you for reading! This is the end of the article on "how to use exit commands in Shell". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 257
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.