I would like to take the output of something that returns lines of elements possibly containing spaces to a bash array, with each line getting its own array element.
So for example:
find . -name \*.jpg
... may return a list of filenames. I want each filename to be assigned to an array. The simple solution doesn't work in general, because if there are spaces in filenames, the words get their own array element.
For example, start with this list of files in a directory:
FILE1.jpg
FILE2.jpg
FILE WITH SPACES.jpg
Try:
FILES=( $(find . -name \*.jpg) )
And you get (<> added for emphasis of individual elements):
$ for f in "${FILES[@]}"; do echo "<$f>"; done
<./FILE>
<WITH>
<SPACES.jpg>
<./FILE1.jpg>
<./FILE2.jpg>
This is not likely what you want.
How do you assign lines to array elements regardless of the lines containing spaces?