exit命令_Linux exit 命令用法详解:退出当前的shell
2018-10-16 13:56
3899 查看
exit命令同于退出shell,并返回给定值。在shell脚本中可以终止当前脚本执行。执行exit可使shell以指定的状态值退出。若不设置状态值参数,则shell以预设值退出。状态值0代表执行成功,其他值代表执行失败。
语法
exit(参数)
参数
返回值:指定shell返回值。
实例
退出当前shell:
[root@localhost ~]# exit logout
在脚本中,进入脚本所在目录,否则退出:
cd $(dirname $0) || exit 1
在脚本中,判断参数数量,不匹配就打印使用方式,退出:
if [ "$#" -ne "2" ]; then echo "usage: $0 <area> <hours>" exit 2 fi
在脚本中,退出时删除临时文件:
trap "rm -f tmpfile; echo Bye." EXIT
检查上一命令的退出码:
./mycommand.sh EXCODE=$? if [ "$EXCODE" == "0" ]; then echo "O.K" fi
相关命令
相关文章推荐
- logout命令_Linux logout 命令用法详解:退出当前登录的Shell
- Linux命令exit - 退出当前shell
- Linux命令之exit - 退出当前shell【返回值状态】
- Linux命令之exit - 退出当前shell【返回值状态】
- 我使用过的Linux命令之exit - 退出当前shell
- Linux命令之exit - 退出当前shell
- Linux命令之exit - 退出当前shell
- Linux命令exit - 退出当前shell
- Linux exit退出目前的shell命令详解
- linux ulimit命令参数及用法详解--linux限定shell启动进程资源
- enable命令_Linux enable 命令用法详解:启动或关闭shell内建命令
- sh命令_Linux sh 命令用法详解:shell命令解释器
- declare命令_Linux declare 命令用法详解:声明或显示shell变量
- runlevel命令_Linux runlevel 命令用法详解:打印当前Linux系统的运行等级
- Linux如何查看系统当前登录用户信息,linux su命令参数及用法详解(linux切换用户命令)
- ps命令_Linux ps 命令用法详解:报告当前系统的进程状态
- builtin命令_Linux builtin 命令用法详解:执行shell内部命令
- chsh命令_Linux chsh 命令用法详解:用来更换登录系统时使用的shell
- eject命令_Linux eject 命令用法详解:用来退出抽取式设备
- linux chsh命令参数及用法详解(linux设置系统shell命令)