2013-08-04 85 views

回答

8

使用return操作者:

function FUNCT { 
    if [ blah is false ]; then 
    return 1 # or return 0, or even you can omit the argument. 
    else 
    keep running the function 
    fi 
} 
34

使用:

return [n] 

help return

回報:迴歸[N]

Return from a shell function. 

Causes a function or sourced script to exit with the return value 
specified by N. If N is omitted, the return status is that of the 
last command executed within the function or script. 

Exit Status: 
Returns N, or failure if the shell is not executing a function or script. 
+3

注意,如果你'設置-e'設定在腳本的頂部,你的'返回1'或0以外的任何其他號碼,您的整個腳本將退出。 –