bash “read -a” looping on null delimited string variable
In bash
4.4, the readarray
command gained a -d
option analogous to the same option for read
.
$ IFS= readarray -d '' myvar < <(printf "%s\0" 'a b' 'c d')$ printf "%s\n" "${myvar[@]}"a bc d
If you must support earlier versions, you need to loop over the output explicitly.
while IFS= read -d '' line; do myvar+=( "$line" )done < <(printf "%s\0" 'a b' 'c d')