exit 和 return

来源:互联网 发布:淘宝买药品要提交需求 编辑:程序博客网 时间:2024/05/21 10:10
 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.shaaaexit ;[oracle@june3 dbi]$ sh ./a2.sh./a2.sh: line 1: aaa: command not found[oracle@june3 dbi]$ echo $?127If neither option is supplied and              an error occurred or command cannot be found, the exit status is 127rerurn 函数:return: can only `return' from a function or sourced script[oracle@june3 dbi]$ cat a4.sh fun() {lsreturn 100}fun[oracle@june3 dbi]$ sh ./a4.sh1  1.pl  2.pl  3.pl  4.pl  5.pl  a1.sha2.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.sh1  1.pl  2.pl  3.pl  4.pl  5.pl  a1.sha2.sh  a3.sh  a4.sh  aa[oracle@june3 dbi]$ echo $?0return 用户返回函数执行的值

0 0