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

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!caen!snark
  3. From: snark@chiasmus.engin.umich.edu (Mark Van Antwerp)
  4. Subject: Re: Reading a line from a file in Bourne
  5. Message-ID: <LdR=s!B@engin.umich.edu>
  6. Date: Fri, 11 Dec 92 18:59:01 EST
  7. Organization: University of Michigan (CAEN)
  8. Distribution: usa
  9. References: <SHUTTON.92Dec11112920@fokker.union.indiana.edu> <GUENTHER.92Dec11140649@quelle.stolaf.edu>
  10. Originator: snark@chiasmus.engin.umich.edu
  11. Nntp-Posting-Host: chiasmus.engin.umich.edu
  12. Lines: 36
  13.  
  14.  
  15. Scott K. Hutton wrote:
  16. -------------------------
  17.   for ITEM in `cat $FILENAME`
  18.        do echo a full line: $ITEM
  19.      done
  20.  
  21.    If you're given a file that contains:
  22.  
  23.      Line one
  24.      Line two
  25.  
  26.    This script would output
  27.  
  28.      a full line: Line
  29.      a full line: one
  30.      a full line: Line
  31.      a full line: two
  32.  
  33.    Any easy answers?
  34. ------------------------
  35.  
  36. Well, the reason it does that is do to the IFS in the bourne
  37. shell.  You can change the IFS or use another command.
  38.  
  39. To change IFS, do:
  40.  
  41. IFS="
  42. "
  43.     This changes it to a newline.
  44.  
  45. Some other ideas are using read or awk.
  46.  
  47.         -snark
  48.  
  49. p.s.  I think IFS defaults to a space and/or tab.
  50.