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

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!highlite!dlreed
  3. From: dlreed@highlite.uucp (David L. Reed)
  4. Subject: Re: Reading a line from a file in Bourne
  5. Message-ID: <1992Dec14.233439.4054@highlite.uucp>
  6. Organization: Gotham Communications Research
  7. References: <SHUTTON.92Dec11112920@fokker.union.indiana.edu> <SHUTTON.92Dec11223107@fokker.union.indiana.edu>
  8. Distribution: usa
  9. Date: Mon, 14 Dec 1992 23:34:39 GMT
  10. Lines: 33
  11.  
  12. shutton@fokker.union.indiana.edu (Scott K. Hutton) writes:
  13.  
  14. >I've received a lot of good advice, both through e-mail and followups.
  15. >The bottom line (while I did receive lots of  innovative solutions) is
  16. >to do something akin to the following:
  17.  
  18. >#!/bin/sh
  19. >cat myfile |
  20. >while read LINE
  21. >do
  22. > echo a full line: $LINE
  23. >done
  24.  
  25. This is good, but avoid a pipe if possible.               
  26.  
  27. The alternative that has worked best for me is to let while take
  28. stdin directly from the file:
  29.  
  30. #!/bin/sh
  31. while read LINE
  32. do
  33.  echo a full line: $LINE
  34. done < myfile
  35.  
  36. >"read"  apparently has a  significant return value--major goof  on  my
  37. >part for failing to check this.
  38.  
  39. >-S
  40. -- 
  41. David L. Reed:  dlreed@gotham.com  dlreed@highlite.uucp  uunet!highlite!dlreed
  42.          Come join us at highlite... Public Access Unix for DC/MD/VA.
  43.    D.C. Metro (301)924-5998, Comms set to 8N1.  login: guest  passwd: guest 
  44.      Taking calls at 1200/2400/9600+ (V.32bis/V.42bis w/error correction)   
  45.