我想调用函数“B”并传递给它将调用的另一个函数名称(A1,A2等)。在这个函数中,通过哪个名字,我初始化了几个变量,但是我不能从“B”函数中读取它们。当函数被撤销时,Bash全局变量没有改变
function A1
{
echo "func 1"
result1="a1"
return 0
}
function A2
{
echo "func 2"
anotherResult="a2"
#..some other initialization
return 0
}
#...
function B
{
output=`$1` # $1 - function name
echo output=$output
echo result1=$result1 # <--- ERROR! result1 is empty!
}
B "A1" # main script runs function B and passes other function name
output ='$ 1'带反引号,没有反斜杠 – 2011-04-11 13:35:16
和B“A1”最后也是bash代码 – 2011-04-11 13:37:25
据此编辑。 – mouviciel 2011-04-11 14:23:48