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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.