User Tools

Site Tools


When you want to save values between functions of your bash script, there are several ways:

  1. Use the same variable name and don't create them as “local” to a function
    function myfunc()
        myresult='some value'
    echo $myresult

    :!: Quite Dangerous :!:

  2. Let you function handle arguments:
    function myfunc()
        local  __resultvar=$1
        local  myresult='some value'
        eval $__resultvar="'$myresult'"
    myfunc result
    echo $result


scripting/bash/returnvar.txt · Last modified: 2020/12/17 05:23 by