On 2008-04-02, Gary R. Schmidt <grschmidt@acm.org> wrote:
Ela wrote:
Dear all,
I found I cannot use a variable name as the input of the command "cat"
followed by piping the result. Could any body tell me how to solve the
problem?
cat $filename |\
while read line
do
echo "$line read from $filename"
done
Try:
while read line
do
echo "$line read from $filename"
done < $filename
Cheers,
Gary
Gary's solution is good for this specific problem. In the more general case, where there's no alternative to piping stdout into a loop, you'll avoid this problem by using ksh and not bash.
-- Christopher Mattern
NOTICE Thank you for noticing this new notice Your noticing it has been noted And will be reported to the authorities
Michael Schmarck 2 April 2008 21:47:51 [ permanent link ]
· Chris Mattern <syscjm@sumire.gwu.edu>:
Gary's solution is good for this specific problem. In the more general
case, where there's no alternative to piping stdout into a loop,
you'll avoid this problem by using ksh and not bash.
What problem? The code that's been posted by the OP works perfectly fine in bash (cf my <news:1249704.yo29TvKFi1@schmarck.cn>).
But you're right though, Garys solution is better than the one posted by the OP, as it avoids a UUOC.
Anyway - I'd *really* be interested in knowing the problem you talk about.
Michael Schmarck -- "You're just the sort of person I imagined marrying, when I was little... except, y'know, not green... and without all the patches of fungus." -- Swamp Thing