浅谈Linux中shell编程的exit命令
浅谈Linux中shell编程的exit命令
exit命令:
(1)用于退出当前shell
(2)在shell脚本中可以终止当前脚本执行
格式:exit n
n为退出码,0-255(默认为0)
常见退出码:
0 成功
1 通常未知错误
2 错误shell命令(如:参数错误)
127 命令未找到
补充:
获取上一个命令退出码
格式:$?
案例:
终止当前脚本执行
#!bin/bash
#exit退出脚本案例
#auth:odysee
for((i=1;i<=10;i++))
do
if ((i==5))
then
exit 11
fi
echo "$i"
done

测试
//打印状态码
echo $?

案例2:
退出当前shell

测试完成
相关推荐
-
PHP8种变量类型的详细讲解2025-02-22 00:32:24
-
php+apache 和 php+nginx的区别2025-02-22 00:21:27
-
PHP:与workerman结合实现定时任务2025-02-22 00:15:57
-
Nginx的Rewrite规则与实例2025-02-22 00:15:39
-
MySql中身份证字段的简单脱敏介绍2025-02-22 00:15:36