From: Randal L. Schwartz on

This Week's Useless Use of Cat Award goes to
Melvin <whereismelvin(a)gmail.com>, who writes:

set string1 = `cat file|tail -1`

And of course, if you've been following along for a week or two, you know
that this (BING!) is a Useless Use of Cat!

Rememeber, nearly all cases where you have:

cat file | some_command and its args ...

you can rewrite it as:

<file some_command and its args ...

and in some cases, such as this one, you can move the filename
to the arglist as in:

some_command and its args ... file

Just another Useless Use of Usenet,

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn(a)stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
From: Seebs on
On 2010-02-23, Randal L. Schwartz <merlyn(a)stonehenge.com> wrote:
> set string1 = `cat file|tail -1`

Nice!

> And of course, if you've been following along for a week or two, you know
> that this (BING!) is a Useless Use of Cat!

I actually did find a fascinating example of a Useful Use of Cat:

cat "$@" | <command>

This converts a plain filter which only works on standard input to a smart
filter which accepts standard input or a list of files. (Assuming a
reasonably modern shell, say, one from the last decade or two.)

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: pk on
Seebs wrote:

> I actually did find a fascinating example of a Useful Use of Cat:
>
> cat "$@" | <command>
>
> This converts a plain filter which only works on standard input to a smart
> filter which accepts standard input or a list of files. (Assuming a
> reasonably modern shell, say, one from the last decade or two.)

That is mentioned in the "Useful Use of Cat" page, which you might be
interested in:

http://www.in-ulm.de/~mascheck/various/uuoc/

where it appears as

cat ${1+"$@"} | command
From: Keith Keller on
On 2010-02-23, pk <pk(a)pk.invalid> wrote:
>
> That is mentioned in the "Useful Use of Cat" page, which you might be
> interested in:
>
> http://www.in-ulm.de/~mascheck/various/uuoc/

That's an awesome page. But I do have a minor nitpick on this one:

"eliminate pager functionality, pagers (like more(1)/less(1)/pg(1))
usually test stdout/stderr for an interactive TTY,
also a simple way to force ps(1) to print long lines (complete
arguments)

script_or_command | cat"

Some versions of ps accept the w switch to get it to print long lines.
And if your script_or_command is just more file, then the above becomes
a Useless Use Of Pipe:

cat file

It's true that some commands do other things but have paging support
built in, in which case you either need a switch to that command turning
off paging or the above pipe to cat.

--keith




--
kkeller-usenet(a)wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information

From: Seebs on
On 2010-02-23, pk <pk(a)pk.invalid> wrote:
> cat ${1+"$@"} | command

I ended up looking into the 1+ thing a while back, and discovered that
apparently the remaining system on which this makes a difference is probably
Tru64. Everything else is newer.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
 | 
Pages: 1
Prev: get the interpreting shell
Next: FS Monitor