Вопрос

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