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