valor - Cómo salir de una función en bash
llamar funciones en shell (2)
Usar operador de 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
}
¿Cómo saldría de una función si una condición es verdadera sin matar toda la secuencia de comandos, simplemente regrese a antes de llamar a la función.
Ejemplo
# Start script
Do scripty stuff here
Ok now lets call FUNCT
FUNCT
Here is A to come back to
function FUNCT {
if [ blah is false ]; then
exit the function and go up to A
else
keep running the function
fi
}
Utilizar:
return [n]
De help return
return : retorno [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.