Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!spool.mu.edu!news.sgi.com!enews.sgi.com!news.mathworks.com!newsfeed.internetmci.com!in3.uu.net!EU.net!main.Germany.EU.net!fu-berlin.de!irz401!orion.sax.de!uriah.heep!news From: j@uriah.heep.sax.de (J Wunsch) Newsgroups: comp.unix.bsd.freebsd.misc Subject: Re: sh command shell script writing. i'm stuck Date: 9 Aug 1996 06:46:30 GMT Organization: Private BSD site, Dresden Lines: 36 Message-ID: <4uems6$2mm@uriah.heep.sax.de> References: <4t02d1$nec@cliff.island.net> <Pine.HPP.3.91.960722171415.29481F-100000@lint.cisco.com> <Dv4rGs.2nv@rockyd.rockefeller.edu> <4toi97$ar@anorak.coverform.lan> Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) NNTP-Posting-Host: localhost.heep.sax.de Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Newsreader: knews 0.9.6 X-Phone: +49-351-2012 669 X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F 93 21 E0 7D F9 12 D6 4E brian@awfulhak.demon.co.uk (Brian Somers) wrote: > With zsh > (I'm told) and ksh (not pdksh), the following is even better: > > x=1 > while read line > do > test $x -eq TheNumberIWant && { > echo $line > break > } > done <input_file This should even work with a plain Bourne shell. while loops are always treated as subshells, and can get separate IO redirection. You can also pipe into a while loop: grep foobar mumble | awk '{print $1 " " $3}' | while read f1 f2 do do something with $f1 and $f2 done Loops of this kind allowed me to install 386BSD off the two dozen floppies on a machine that did not have the disk space to hold a temporary copy of the installation files... (with prompting for the next floppy inside the loop etc.). ;-) -- cheers, J"org joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-)