home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / shell / 3956 < prev    next >
Encoding:
Internet Message Format  |  1992-09-15  |  1.7 KB

  1. Path: sparky!uunet!olivea!spool.mu.edu!uwm.edu!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!nucsrl!ddsw1!dattier
  2. From: dattier@ddsw1.mcs.com (DWT)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: clever `cat' commmand?
  5. Message-ID: <BuMMnv.AsM@ddsw1.mcs.com>
  6. Date: 15 Sep 92 15:50:18 GMT
  7. References: <1992Sep14.173218*Harald.Eikrem@delab.sintef.no> <lb9kc0INN78u@news.bbn.com>
  8. Organization: Contributor Account at ddsw1, Chicago, Illinois  60657
  9. Lines: 35
  10.  
  11. cjross@bbn.com (chris ross) wrote in <lb9kc0INN78u@news.bbn.com>:
  12.  
  13. | Harald.Eikrem@delab.sintef.no writes:
  14. | >For once, a question.  Can anyone think of the simplest means of making
  15. | >a utility that behaves like `cat(1)', but exits with 0 if something went
  16. | >through it, otherwise 1?  Preferrably a one-liner......
  17. | >I've tried:   awk '{ s=1; print; }; END{ if(s) exit 0; exit 1; }'
  18. | >which is ok with a line oriented input stream, but not with a "binary" 
  19. | >stream.
  20. | Your grep may be able to accomplish this.
  21. | Use grep -s if you don't want the output.
  22. |   $ echo foo | grep .
  23. |   foo
  24. |   $ echo $?
  25. |   0
  26. |   $ cat </dev/null | grep .
  27. |   $ echo $?
  28. |   1
  29.  
  30. The problem is that a file consisting only of newlines will also return 1 if
  31. you grep for .; grep for ^ or $.  You may need to escape either or both of
  32. those in your shell, of course.
  33.  
  34. I guess ^ is better because if binary data has no bytes of decimal 10, grep
  35. may decide that $ isn't there because nothing is immediately before a line-
  36. feed, but there will always be a first character in the file unless it is
  37. totally empty.
  38.  
  39. David W. Tamkin   Box 59297   Northtown Station, Illinois  60659-0297
  40. dattier@ddsw1.mcs.com    CompuServe: 73720,1570    MCI Mail: 426-1818
  41.