You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
643 B

5 years ago
# exit
7 years ago
6 years ago
## 说明
7 years ago
5 years ago
**exit命令** 同于退出shell并返回给定值。在shell脚本中可以终止当前脚本执行。执行exit可使shell以指定的状态值退出。若不设置状态值参数则shell以预设值退出。状态值0代表执行成功其他值代表执行失败
7 years ago
5 years ago
## 实例
7 years ago
5 years ago
```bash
cd $(dirname $0) || exit 1 # 在脚本中,进入脚本所在目录,否则退出
trap "rm -f tmpfile; echo Bye." exit # 在脚本中,退出时删除临时文件
7 years ago
5 years ago
# 在脚本中,判断参数数量,不匹配就打印使用方式,退出
7 years ago
if [ "$#" -ne "2" ]; then
echo "usage: $0 <area> <hours>"
exit 2
fi
```