Jericon
Jericon

Reputation: 5172

Unable to use array with multi-word values

I'm working on a script that requires me to have an array with a multi-word value in it. This needs to be treated on its own.

all=( "test phrase" 4 11 13 )

for i in ${all@]}; do
        echo $i
done

I get out of it:

test
phrase
4
11
13

and I need to get:

test phrase
4
11
13

How can I do this?

Upvotes: 3

Views: 945

Answers (1)

rob mayoff
rob mayoff

Reputation: 385500

You need quotes:

for i in "${all[@]}"; do
    echo "$i"
done

Upvotes: 8

Related Questions