Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnews!smk From: smk@cbnews.cb.att.com (stephen.m.kennedy) Newsgroups: comp.unix.shell Subject: Re: How to read sequentially from a file in SH (not KSH) Message-ID: <1991Apr29.114606.152@cbnews.cb.att.com> Date: 29 Apr 91 11:46:06 GMT References: <1991Apr27.012336.2732@shibaya.lonestar.org> <232@bria.UUCP> Distribution: na Organization: AT&T Bell Laboratories Lines: 34 >In an article, afc@shibaya.lonestar.org (Augustine Cano) writes: > >while read VAR1 VAR2 < $FILENAME; do > echo $VAR1 $VAR2 >done > >but I keep reading the first line in the file over and over. Nothing in >the manual page seems to be usable in this situation. How is this done >under SH? Is it possible? How about: exec 3<$FILENAME while read VAR1 VAR2 0<&3; do echo $VAR1 $VAR2 done exec 3<&- # any variable set in while loop will still be set here # ... or: readit() { while read VAR1 VAR2; do echo $VAR1 $VAR2 done } readit <$FILENAME Steve Kennedy smk@cbosgd.att.com