[TriLUG] possible awk/grep question
Paul McLanahan
pmclanahan at gmail.com
Thu Jan 17 21:04:50 EST 2008
On Jan 17, 2008 2:17 PM, Joseph Mack NA3T <jmack at wm7d.net> wrote:
> any idea why I can't get the original version to work?
>
>
This is just a WAG mind you, but I believe it has to do with the "<"
operator expecting a file name, and so it's evaluating your command in the
backticks and then attempting to use the output as a file name, which fails.
I could be very very wrong though :)
I have, however, gotten the following syntax to work. This syntax is only
superior to the pipe method mentioned above when you need to maintain
context inside the loop. When you use the pipe, the loop executes in a
sub-shell, and therefore all variables created or modified inside the loop
are not available after the loop. I had to use this because I was collecting
information in a variable inside a loop which I wanted to use later in the
script, and when I tried that using the "command | while read line; do"
syntax, I lost my context.
while read line
do
collection="$collection $line"
done < <(command)
# do stuff with $collection ...
That should work exactly the same way as the pipe method if all you're doing
is echoing from inside the loop. Perhaps someone more advanced can better
explain the < <(command) syntax, and how it's different from < $(command) or
< `command`.
HTH,
Paul
More information about the TriLUG
mailing list