Return value from a function

suggest change

The return statement in Bash doesn’t return a value like C-functions, instead it exits the function with a return status. You can think of it as the exit status of that function.

If you want to return a value from the function then send the value to stdout like this:

fun() {
    local var="Sample value to be returned"
    echo "$var"
    #printf "%s\n" "$var"
}

Now, if you do:

var="$(fun)"

the output of fun will be stored in $var.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents