In bash I frequently make scripts where I loop over a list of strings that I define.
e.g.
for a in 1 2 3 4; do echo $a; done
However I would like to define the list (before the loop to keep it clean) so that it contains spaces and with out a separate file:
e.g. (BUT THIS WILL NOT WORK)
read -r VAR <<HERE
list item 1
list item 2
list item 3
...
HERE
for a in $VAR; do echo $a; done
The expected output above (I would like):
list item 1
list item 2
list item 3
etc...
But you will get:
list
item
1
I could use arrays but I would have to index each element in the array (EDIT read answers below as you can append to arrays.. I did not know you could).
How do others declaratively define lists in bash with out using separate files?
Sorry I forgot to mention I want to define the list at the top of the file before the for loop logic