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