I'm passing data from STDIN
into an array using read
like so:
prompt$ cat myfile
a "bc" "d e" f
prompt$ read -a arr < myfile
But read
doesn't appear to pay attention to the quoted strings and provides me an array of 5 elements:
prompt$ echo ${#arr[@]}
5
prompt$ echo ${arr[@]:0}
a "bc" "d e" f
prompt$ echo ${arr[2]}
"d
prompt$ echo ${arr[3]}
e"
I'm using the default IFS
setting: \t\n
in bash
.
There are several ways to accomplish task using different tools, but I'm surprised that read doesn't support quoted strings.
Any other suggestions for getting a delimited list with quotes into an array?