home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / shell / 5040 < prev    next >
Encoding:
Text File  |  1992-12-11  |  2.1 KB  |  52 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!wupost!uwm.edu!psuvax1!atlantis.psu.edu!barr
  3. From: barr@pop.psu.edu (David Barr)
  4. Subject: Re: Reading a line from a file in Bourne
  5. Message-ID: <4821Hpbsab@atlantis.psu.edu>
  6. Sender: news@atlantis.psu.edu (Usenet)
  7. Organization: Penn State Population Research Institute
  8. References: <SHUTTON.92Dec11112920@fokker.union.indiana.edu>
  9. Distribution: usa
  10. Date: Sat, 12 Dec 92 00:23:37 GMT
  11. Lines: 39
  12.  
  13. In article <SHUTTON.92Dec11112920@fokker.union.indiana.edu> shutton@fokker.union.indiana.edu (Scott K. Hutton) writes:
  14. >This is something that has eluded me  for a good while, but now I have
  15. >to find out.  How can  you read lines (yes, entire lines) sequentially
  16. >in from a file and store them in a variable.
  17.  
  18. Well, if you read the man page to sh, you would have found 
  19. (something like) this:
  20.  
  21.      read [ name ... ]
  22.                     One line is read from the standard input and,
  23.                     using the internal field separator, IFS (nor-
  24.                     mally a SPACE or TAB character),  to  delimit
  25.                     word  boundaries,  the first word is assigned
  26.                     to the first name, the  second  word  to  the
  27.                     second   name,   etc.,  with  leftover  words
  28.                     assigned to the last name.  Lines can be con-
  29.                     tinued using \NEWLINE.  Characters other than
  30.                     NEWLINE can be quoted by preceding them  with
  31.                     a  backslash.   These backslashes are removed
  32.                     before words are assigned to  names,  and  no
  33.                     interpretation  is done on the character that
  34.                     follows the backslash.  The return code is  0
  35.                     unless an EOF is encountered.
  36. -------
  37.  
  38. If you want to read a specific file instead of standard input,
  39. do something like this:
  40.  
  41. #!/bin/sh
  42. exec </etc/resolv.conf
  43. read foo domain
  44. read foo nameserver
  45. echo your domain is $domain
  46. echo this machine\'s first nameserver is $nameserver
  47.  
  48. --Dave
  49. -- 
  50. System Administrator, Population Research Institute    barr@pop.psu.edu
  51. #define ENOTTY          25              /* Not a typewriter */
  52.