html tool

2017年11月28日星期二

How to return a string value from a Bash function

https://stackoverflow.com/questions/3236871/how-to-return-a-string-value-from-a-bash-function


You could have the function take a variable as the first arg and modify the variable with the string you want to return.
#!/bin/bash
set -x
function pass_back_a_string() {
    eval "$1='foo bar rab oof'"
}

return_var=''
pass_back_a_string return_var
echo $return_var
Prints "foo bar rab oof".

没有评论:

发表评论