exit [n]
Cause the shell to exit with a status of n. If n is omitted, the exit status is that of the last command executed. A trap on EXIT is executed before the shell ter-minates.
设置shell 退出时候的状态码,如果n 没有设置,退出状态是上次执行命令
[oracle@june3 dbi]$ cat a1.sh
exit 10;
[oracle@june3 dbi]$ sh ./a1.sh
[oracle@june3 dbi]$ echo $?
10
[oracle@june3 dbi]$ cat a2.sh
aaa
exit ;
[oracle@june3 dbi]$ sh ./a2.sh
./a2.sh: line 1: aaa: command not found
[oracle@june3 dbi]$ echo $?
127
If neither option is supplied and
an error occurred or command cannot be found, the exit status is 127
rerurn 函数:
return: can only `return' from a function or sourced script
[oracle@june3 dbi]$ cat a4.sh
fun() {
ls
return 100
}
fun
[oracle@june3 dbi]$ sh ./a4.sh
1 1.pl 2.pl 3.pl 4.pl 5.pl a1.sh a2.sh a3.sh a4.sh aa
[oracle@june3 dbi]$ echo $?
100
[oracle@june3 dbi]$ cat a4.sh
fun() {
ls
#return 100
}
fun
[oracle@june3 dbi]$ sh ./a4.sh
1 1.pl 2.pl 3.pl 4.pl 5.pl a1.sh a2.sh a3.sh a4.sh aa
[oracle@june3 dbi]$ echo $?
0
return 用户返回函数执行的值