1
鉴于下面的字符串变量传递与空格的字符串作为参数传给击功能
VAR="foo bar"
我需要它被传递给一个bash功能,并访问它,按照惯例,通过$1
。到目前为止,我一直无法弄清楚如何做到这一点:
#!/bin/bash
function testfn(){
echo "in function: $1"
}
VAR="foo bar"
echo "desired output is:"
echo "$(testfn 'foo bar')"
echo "Now, what about a version with \$VAR?"
echo "Note, by the way, that the following doesn't do the right thing:"
echo $(testfn "foo bar") #prints: "in function: foo bar"
对。我假定不应该使用嵌套的双引号。然而,'echo“(testfn”$ VAR“)”'工作得很好。 – 2010-10-27 08:16:26