문제

say we have:

test() {
    echo $1
    echo $2
}

and two variables:

a="hello world"
b="$a blabla.."

test $b

it displays:

hello
world

what I want is:

hello world
blabla..

How can I achieve this?

Thanks

도움이 되었습니까?

해결책

Use this:

a="hello world"
b="'$a' blabla"
eval "test $b"

The single-quotes are needed to keep hello world together as a single argument. Then you need to use eval because quotes are not normally processed after variable expansion.

다른 팁

You want b to be an array, otherwise there's no way with a single string containing whitespace to determine which space char is the separator:

mytest() {
    echo "$1"
    echo "$2"
}

a="hello world"
b=( "$a" "blah blah" )

mytest "${b[@]}"
hello world
blah blah
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top