退出當(dāng)前的shell。
exit [n]
n(可選):指定的shell返回值(整數(shù))。
返回值為你指定的參數(shù)n的值,如果你指定的參數(shù)大于255或小于0,那么會(huì)通過(guò)加或減256的方式使得返回值總是處于0到255之間。
退出當(dāng)前shell:
[root@localhost ~]# exit
logout
也可以使用ctrl+d
退出當(dāng)前終端,下面列出了打開或關(guān)閉該功能的方法:
# 打開ctrl+d退出終端
set -o ignoreeof
# 關(guān)閉ctrl+d退出終端
set +o ignoreeof
在腳本中,進(jìn)入腳本所在目錄,否則退出:
cd $(dirname $0) || exit 1
在腳本中,判斷參數(shù)數(shù)量,不匹配就打印使用方式,退出:
if [ "$#" -ne "2" ]; then
echo "usage: $0 <area> <hours>"
exit 2
fi
在腳本中,退出時(shí)刪除臨時(shí)文件:
trap "rm -f tmpfile; echo Bye." EXIT
檢查上一命令的退出碼:
./mycommand.sh
EXCODE=$?
if [ "$EXCODE" == "0" ]; then
echo "O.K"
fi
help
命令。