How do I recollect my password?
using pipe in shell script
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• RYXI
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

RYXI > Solaris > using pipe in shell script 2 April 2008 21:47:51

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

using pipe in shell script

Ela 2 April 2008 21:47:51
 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



Add comment
Gary R. Schmidt 2 April 2008 09:41:25 permanent link ]
 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 B-)­
Add comment
Michael Schmarck 2 April 2008 10:32:14 permanent link ]
 Ela <ela@yantai.org> 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?

And what's the problem? Your code works just fine (with bash).
What does not work for you?

--($:~)-- cat $filename | while read line ; do echo "$line read from $filename" ; done
:set hlsearch read from .vimrc
--($:~)-- echo $filename
.vimrc

BTW: That was UUOC. Better to do:

while read line; do echo "$line read from $filename"; done < $filename

Michael
Add comment
Chris Mattern 2 April 2008 20:06:51 permanent link ]
 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 B-)­

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
Add comment
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.yo29T­vKFi1@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

Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


RYXI > Solaris > using pipe in shell script 2 April 2008 21:47:51

see also:
How to allow an ipsec tunnel endpoint…
connections are dropped over ipsec…
Explanation of Lokkit?
пройди тесты:
see also:
converting mp3 file to midi file
Pencil and pastel portraits by this...
looking at mackie products for a good…

  Copyright © 2001—2008 RYXI
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.ryxi.com.
Сообщения об ошибках оставляем в сообществе bugs.ryxi.com.
Предложения и комментарии пишем в сообществе suggest.ryxi.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .