How to read a string into an array and get values ​​from an array

I currently have

DATE_LIST=$(cat "$OUT_FILE" | xmlstarlet sel -T -t -m "//*[local-name()='entry']//*[local-name()='$start_position_date'][@name='beginposition']" -v '.' -n)

      

The result looks something like this:

DATE_LIST= 2015-10-10
2015-11-11

      

... etc.

IFS='\n' read -a array <<< "$DATE_LIST"

echo "${array[0]}" //I get the first one
echo "${array[1]}" //I get nothing

      

How to disassemble it correctly? DATE_LIST

generated from xml and strings are split \n

.

+3


source to share


1 answer


This adds each line from the output to the array, maintaining lines with withespaces.



array=()
IFS='
'
for line in $(cat "$OUT_FILE" | xmlstarlet set -T ...)
do
    array+=("$line")
done
unset IFS

      

0


source







All Articles