Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top