2013-08-04 43 views

Trả lời

8

Sử dụng return điều hành:

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

Sử dụng:

return [n] 

Từ help return

trở: 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

Lưu ý rằng nếu bạn có 'thiết lập -e' đặt ở phía trên cùng của kịch bản của bạn và của bạn' 1' trở hoặc bất kỳ số nào khác ngoài 0, toàn bộ của bạn tập lệnh sẽ thoát. –

Các vấn đề liên quan