How to call a shell function
13,663
Solution 1
The exit code is contained in $?
:
fun 2
a=$?
Solution 2
you may have a look at the following question: https://stackoverflow.com/questions/8742783/returning-value-from-called-function-in-shell-script with a long and well explained answer. Regards.
Related videos on Youtube
Comments
-
g4ur4v almost 2 years
How can I use the integer value returned by a function in shell script that takes some arguments as input?
I am using the following code:
fun() { echo "hello ${1}" return 1 } a= fun 2 echo $a
I am not sure how should I call this function. I tried the methods below, bot none of them seems to work:
a= fun 2 a=`fun 2` a=${fun 2}
-
Wildcard over 8 yearsFYI, this uses a nonstandard function definition syntax.