2013-08-04 4 views
25

में किसी फ़ंक्शन से बाहर निकलने के लिए कैसे करें यदि कोई स्क्रिप्ट पूरी स्क्रिप्ट को मारने के बिना सत्य हो, तो फ़ंक्शन से बाहर निकलें, बस फ़ंक्शन कहने से पहले वापस लौटें।बैश

उदाहरण

उत्तर

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 के अतिरिक्त कोई अन्य नंबर, अपने पूरे लिपि बाहर निकल जाएगी। –