home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!uunet.ca!wildcan!sq!msb
- From: msb@sq.sq.com (Mark Brader)
- Subject: Re: clever `cat' commmand?
- Message-ID: <1992Sep15.022614.12085@sq.sq.com>
- Organization: SoftQuad Inc., Toronto, Canada
- References: <1992Sep14.173218*Harald.Eikrem@delab.sintef.no> <lb9kc0INN78u@news.bbn.com>
- Date: Tue, 15 Sep 92 02:26:14 GMT
- Lines: 35
-
- > 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 [an awk solution]
- > which is ok with a line oriented input stream, but not with a "binary"
- > stream.
-
- Many of the utilities commonly used to build shell scripts don't work
- reliably with "binary" streams, so this isn't surprising. The proposed
- solution "grep ." suffers from this problem, and in addition the pattern
- "." is wrong; it should be, say, "^" to match even empty lines.
-
- One utility that does work on binary streams is dd. The version I'm familiar
- with has the additional property that it verbosely outputs count information
- on stderr. On the system I'm typing this on, the following sh one-liner
- does exactly what is wanted:
-
- (dd 2>&1 >&3 | grep -s -v '^0+0 ') 3>&1
-
- The '^0+0 ' matches both lines of dd's stderr when nothing was passed through,
- and neither line otherwise.
-
- dd doesn't take filename arguments in the usual way, so prefix this with
-
- cat "$@" |
-
- if you want arguments to be interpreted as in cat. Sufficiently old sh's
- may require something more verbose than "$@" to correctly handle the case
- of zero arguments.
- --
- Mark Brader "You have a truly warped mind.
- SoftQuad Inc., Toronto I admire that in a person."
- utzoo!sq!msb, msb@sq.com -- Bill Davidsen
-
- This article is in the public domain.
-