home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!darwin.sura.net!jvnc.net!rutgers!cmcl2!hsdndev!news.cs.umb.edu!mzraly
- From: mzraly@cs.umb.edu (Michael S. Zraly)
- Newsgroups: comp.unix.questions
- Subject: Re: Bourne shell read command
- Message-ID: <1992Jul26.055745.5445@cs.umb.edu>
- Date: 26 Jul 92 05:57:45 GMT
- References: <1992Jul24.213654.29656@cs.umb.edu>
- Sender: news@cs.umb.edu (USENET News System)
- Organization: UMass/Boston Dept. of Math & CS
- Lines: 37
- Nntp-Posting-Host: cs.umb.edu
-
- I wrote:
- >
- >I am looking to read a file containing lines of the form
- >
- > field1 field2 field3
- >
- >from a shell file, setting the variables mac to field2 and
- >dir to field3 if field1 matches the variable abbrev.
- >
- >The following code does NOT work, but illustrates my meaning:
- >
- > # this does NOT work
- > while (read x y z junk < $afile)
- > do
- > if test $x = $abbrev
- > then
- > mac=$y # 'export mac' doesn't help
- > dir=$z
- > fi
- > done
- >
- >Does anyone have any ideas?
-
- Oh well, its simpler than I thought:
-
- # this DOES work
- str=`grep "^$abbrev" $afile`
- mac=`echo "$str" | awk '{ print $2 }'`
- dir=`echo "$str" | awk '{ print $3 }'`
-
- Nobody replied, but I thought someone else might want to know.
-
- -- Mike
-
- --
- Mike Zraly If you wanna end war 'n' stuff, you gotta
- mzraly@cs.umb.edu sing LOUD! -- Arlo Guthrie
-