[mdlug] UNIX tips: Learn 10 good UNIX usage habits

Robert Citek robert.citek at gmail.com
Mon Mar 10 04:51:25 EDT 2008


On Mon, Mar 10, 2008 at 2:19 AM, Michael Corral <micorral at comcast.net> wrote:
> 2008-03-10, Monsieur Robert Citek a ecrit:
>
> > contrast the output of these commands:
>
> > $ cat /etc/passwd /etc/group | grep root
>  > $ grep root /etc/passwd /etc/group
>
>  grep -h root /etc/passwd /etc/group
>
>  That will give the same output as the cat+pipe version.
>  So calling cat is unnecessary in this example, since the one grep
>  command does the same as two commands and a pipe.

Agreed.

But my point was about not taking that rule (or any of the rules) as
dogma.  Sometimes maintaining a pattern is more important than
execution efficiency.  In many cases, I find the pattern "$prog1
$files | $prog2" easier and more consistent to work with.  So I'll use
it, regardless if $prog1 is cat or if $files expands to only one file.

Besides, if I'm worrying about execution efficiency, I should probably
be writing the program in C and not in shell.

Regards,
- Robert



More information about the mdlug mailing list