On Thu, Jun 19, 2003 at 06:16:10PM +1200, Christopher Sawtell wrote:
> On Thu, 19 Jun 2003 16:42, you wrote:
> > On Thu, Jun 19, 2003 at 03:29:13PM +1200, Rex wrote:
> > > cat xxxx.1 | nroff -man
> >
> > 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
> What you say is all very true and all, BUT if you mis-type the '<' character 
> and put a '>' by mistake, all hell breaks loose because you have just erased 
> your precious input file. mis-typing < with > is actually horribly easy, they 
> are after all right next to each other. Been caught once and now _always_ use 
> the 'cat file | command -flags ... ' construct.

I don't see how it's easy to mistype the redirection operator, then type
the whole filename and not notice before you hit enter.  You should be
reading the command line before you hit enter, and by the time you've
had to type the filename after the redirection operator, you've got a
pretty good chance to spot your error.

While your reasoning for using 'cat' has a small amount of use on an
interactive command line, it does not have any place in a (well written)
shell script.

Additionally to that, you can set noclobber in your shell, after which
the shell will not overwrite existing files using the '>' (and other)
redirection operator(s).

Cheers,
-mjg
-- 
Matthew Gregan                     |/
                                  /|                [EMAIL PROTECTED]

Reply via email to