0

I need to add values into an array, but some values are separated with a whitespace. Then would be so fo example: "hello world"

myarr[0]: "hello 
myarr[1]: world"

How can I put it all together? For example:

myarr[0]: "hello world"
myarr[1]: "ciao mondo"
myarr[2]: ...
1

1 Answer 1

0

Use quotes around your strings with spaces :

ar+=("hello world" "ciao mondo")

echo ${ar[0]}
hello world

echo ${ar[1]}
ciao mondo

If you use the array in a loop, use quotes around the array:

for x in "${ar[@]}"; do echo "$x"; done
hello world
ciao mondo

Not the answer you're looking for? Browse other questions tagged or ask your own question.