Skip to main content
added 10 characters in body
Source Link
user147505
user147505

You can also do it another way.

_foo () 
{ 
    local _retval
    declare -n output="$1"     # $output is local (by default with declare in a functionfunc.)
                               ## and points to $1
    output="baz" && false
    _retval=$?
    echo ${_retval}            # change echo to exit
}

Now call _foo this way:

$ _foo bar
1
$ echo "$bar"
baz

When you change echo to exit in the function definition, the exit will exit the script.

You can also do it another way.

_foo () 
{ 
    local _retval
    declare -n output="$1"     # $output is local (by default in a function)
                               ## and points to $1
    output="baz" && false
    _retval=$?
    echo ${_retval}            # change echo to exit
}

Now call _foo this way:

$ _foo bar
1
$ echo "$bar"
baz

When you change echo to exit in the function definition, the exit will exit the script.

You can also do it another way.

_foo () 
{ 
    local _retval
    declare -n output="$1"     # $output is local (by default with declare in a func.)
                               ## and points to $1
    output="baz" && false
    _retval=$?
    echo ${_retval}            # change echo to exit
}

Now call _foo this way:

$ _foo bar
1
$ echo "$bar"
baz

When you change echo to exit in the function definition, the exit will exit the script.

Source Link
user147505
user147505

You can also do it another way.

_foo () 
{ 
    local _retval
    declare -n output="$1"     # $output is local (by default in a function)
                               ## and points to $1
    output="baz" && false
    _retval=$?
    echo ${_retval}            # change echo to exit
}

Now call _foo this way:

$ _foo bar
1
$ echo "$bar"
baz

When you change echo to exit in the function definition, the exit will exit the script.