Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use array with multi-word values

Tags:

arrays

bash

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?

like image 585
Jericon Avatar asked Jan 23 '26 07:01

Jericon


1 Answers

You need quotes:

for i in "${all[@]}"; do
    echo "$i"
done
like image 55
rob mayoff Avatar answered Jan 24 '26 22:01

rob mayoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!