Shell tips and tricks (was: cat pipe)

Tom Buskey tom at buskey.name
Fri Oct 5 10:12:37 EDT 2007


On 10/5/07, Ben Scott <dragonhawk at gmail.com> wrote:
>
> On 10/4/07, Michael ODonnell <michael.odonnell at comcast.net> wrote:
> > Bash users can do this:
> >
> >    cp <( date ) /dev/tty
>
>   I had to look that up.  "Process Substitution".  Assuming I
> understand correctly, that connects the output of the "date" command
> to a named pipe (say, /tmp/foo), and then substitutes the name of said
> pipe for the actual argument.  So after substitution, the command
> would look like:
>
>         cp /tmp/foo /dev/tty
>
>   Obviously, your example is a pointless example, but even so... I'm
> trying to think what possible use this would be.  Why would you want
> to use Process Substitution for real?
>
>   The only thing I could think of would be for lame programs which
> insist on read/writing to a named file, and will not use stdin/stdout
> in the manner of a Unix filter.  But I've always just done:
>
>         foo | lameprog /dev/stdin
>
> or whatever for such cases.


That has a huge advantage in readability.  Any shell scripter will
understand that.  Even you had to look that one up.

Perhaps this could apply to cat file | grep instead of < file grep as well.
Most scripters will know the cat example where < file will be less well
known.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.gnhlug.org/mailman/private/gnhlug-discuss/attachments/20071005/68b3ac07/attachment-0001.html 


More information about the gnhlug-discuss mailing list