home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!wupost!uwm.edu!psuvax1!atlantis.psu.edu!barr
- From: barr@pop.psu.edu (David Barr)
- Subject: Re: Reading a line from a file in Bourne
- Message-ID: <4821Hpbsab@atlantis.psu.edu>
- Sender: news@atlantis.psu.edu (Usenet)
- Organization: Penn State Population Research Institute
- References: <SHUTTON.92Dec11112920@fokker.union.indiana.edu>
- Distribution: usa
- Date: Sat, 12 Dec 92 00:23:37 GMT
- Lines: 39
-
- In article <SHUTTON.92Dec11112920@fokker.union.indiana.edu> shutton@fokker.union.indiana.edu (Scott K. Hutton) writes:
- >This is something that has eluded me for a good while, but now I have
- >to find out. How can you read lines (yes, entire lines) sequentially
- >in from a file and store them in a variable.
-
- Well, if you read the man page to sh, you would have found
- (something like) this:
-
- read [ name ... ]
- One line is read from the standard input and,
- using the internal field separator, IFS (nor-
- mally a SPACE or TAB character), to delimit
- word boundaries, the first word is assigned
- to the first name, the second word to the
- second name, etc., with leftover words
- assigned to the last name. Lines can be con-
- tinued using \NEWLINE. Characters other than
- NEWLINE can be quoted by preceding them with
- a backslash. These backslashes are removed
- before words are assigned to names, and no
- interpretation is done on the character that
- follows the backslash. The return code is 0
- unless an EOF is encountered.
- -------
-
- If you want to read a specific file instead of standard input,
- do something like this:
-
- #!/bin/sh
- exec </etc/resolv.conf
- read foo domain
- read foo nameserver
- echo your domain is $domain
- echo this machine\'s first nameserver is $nameserver
-
- --Dave
- --
- System Administrator, Population Research Institute barr@pop.psu.edu
- #define ENOTTY 25 /* Not a typewriter */
-