I am trying to parse a series of output lines that contain a mix of values and strings.
I thought that the set
command would be a straightforward way to do it.
An initial test seemed promising. Here's a sample command line and its output:
$ (set "one two" three; echo $1; echo $2; echo $3)
one two
three
Obviously I get two variables echoed and nothing for the third.
However, when I put it inside my script, where I'm using read
to capture the output lines, I get a different kind of parsing:
echo \"one two\" three |
while read Line
do
echo $Line
set $Line
echo $1
echo $2
echo $3
done
Here's the output:
"one two" three
"one
two"
three
The echo $Line
command shows that the quotes are there but the set
command does not use them to delimit a parameter. Why not?
In researching the use of read
and while read
I came across the while IFS= read
idiom, so I tried that, but it made no difference at all.
I've read through dozens of questions about quoting, but haven't found anything that clarifies this for me. Obviously I've got my levels of quoting confused, but where? And what might I do to get what I want, which is to get the same kind of parsing in my script as I got from the command line?
Thanks.