Jak wyjść z funkcji, jeśli warunek jest prawdziwy, bez zabicia całego skryptu, po prostu wróć do przed wywołaniem funkcji.Jak wyjść z funkcji w bashu
Przykład
Jak wyjść z funkcji, jeśli warunek jest prawdziwy, bez zabicia całego skryptu, po prostu wróć do przed wywołaniem funkcji.Jak wyjść z funkcji w bashu
Przykład
Zastosowanie return
operatora:
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
}
Zastosowanie:
return [n]
Z help return
powrót: powrót [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.
Pamiętaj, że jeśli masz 'set -e' ustawić na górze skryptu i twój powrót' 1 'lub inny numer oprócz 0, całą skrypt zakończy działanie. –