当前位置:网站首页>Exit of shell internal value command

Exit of shell internal value command

2022-06-26 07:23:00 TimeFriends

Shell Internal value command exit

 Introduce :
	exit  Used to exit the current shell The environment process ends running , And you can return a status code . In general use $? You can get the status code .

 grammar :
	 Correct exit Syntax  exit # The default return status code 0 , Generally, it means that the command is executed successfully 
	 Bad exit Syntax  exit  Not 0 Numbers  # Range of digital recommendations 0-255  Generally, it means that the command execution fails 

exit Application scenarios 
	1. End the present shell process 
	2. When shell An error occurred while the process was executing. When exiting , Different status values can be returned to represent different errors .
		 For example, when operating a file in a script file , Can return 1 Indicates that the file does not exist ,2 Indicates that the file does not have read permission ,3 Indicates that the file type is incorrect .
example

demand : To write shell Script use exit sign out , When exiting, return a non 0 Digital status value , Execute the script file and print the return status value

step :

​ 1. establish exit.sh file

​ 2. edit exit.sh file , Use exit Digital exit ends the current shell

​ 3. Executable files , Print the return status value

demonstration
vim exit.sh

#!/bin/bash
echo 'hello'
exit 2
echo 'word'


# perform  exit.sh
sh exit.sh # Only output  hello
echo $? # Output 2  Get the status code returned by the last command execution 
Summary
exit Application scenarios of 
	 End the present shell process 
	 You can return different status codes , Used for different business processing 
原网站

版权声明
本文为[TimeFriends]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202171129373280.html

随机推荐