[DISCUSS] 10 Good Unix command line habits

Ed Allen era at jimani.com
Thu Dec 21 12:43:29 CST 2006


> ----- Forwarded message from Luke-Jr <luke at dashjr.org> -----
> Notes:
> In "Quote variables with caution", it says to use square brackets, and then 
> goes on to give a correct example with curly braces.
> "Stop piping cats" only refers to piping to grep, but in reality there's 
> almost never a good reason to pipe a single-file cat. The < operator provides 
> a file on standard input. So "cat foo | wc -l" can become "wc -l < foo"
> 
An easy to see case where 'cat' is truly the easiest way...


(cat /tmp/header; date; uptime;cat - /tmp/signature) | \
     mail -s 'A case where cat is needed' kclug at kclug.org

The ( ) pair spawns s sub-shell which allows multiple commands to
share the same input, output, and error streams.

In this case I used 'date' and 'uptime' along with a second 'cat'.

The second 'cat' reads from stdin (standard in) till it sees EOF
(End Of File <Control-D>) and then follows that with the
/tmp/signature file.

Stdout of all those commands is sent to stdin of the 'mail' command.


More information about the Kclug mailing list