shell脚本中exit命令

2020-09-30 10:19:54

exit命令用于退出当前shell,在shell脚本中可以终止当前脚本执行。

$ exit --help
exit: exit [n]
    Exit the shell.

    Exits the shell with a status of N.  If N is omitted, the exit status
    is that of the last command executed.

常用方法:

格式:exit n
退出shell脚本,并设置退出码为n。

格式:exit
退出shell脚本,退出码为最后一个命令的退出码(即 $?)。

格式:trap “commands” EXIT
退出前执行commands指定的命令。

常用退出码

0表示成功(Zero - Success)

非0表示失败(Non-Zero - Failure)

2表示用法不当(Incorrect Usage)

127表示命令没有找到(Command Not Found)

126表示不是可执行的(Not an executable)

128 信号产生

posted @   QIYUEXIN  阅读(831)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示