Home > database >  Bash: Adding an element to a list where elements may or may not have spaces
Bash: Adding an element to a list where elements may or may not have spaces

Time:01-15

According to several threads in SO, I've developed the following mini-script:

list=(Alabama Alaska "New York")

list=$list" Oregon"

for state in  "${list[@]}"
do
    echo The next state is $state
done

The problem is that the output is

The next state is Alabama Oregon
The next state is Alaska
The next state is New York

instead of

The next state is Alabama 
The next state is Alaska
The next state is New York
The next state is Oregon

How would I append the element Oregon?

CodePudding user response:

list =("Oregon")

See this answer: https://stackoverflow.com/a/39935409/2840436

  •  Tags:  
  • bash
  • Related