[lug] Bletcherous pipe, FIXME!

Zan Lynx zlynx at acm.org
Thu Apr 2 16:10:45 MDT 2009


Jeffrey Haemer wrote:
> 
>     Use echo instead of printf.  Echo is generally a shell builtin.
>
> 
> FWIW, printf is a builtin, too, at least in bash and dash.  Also in 
> csh/tcsh on my Mac.  Doesn't look like it is in busybox's ash.  Though 
> in busybox, everything is sort of a built-in. :-)  

Huh.  I didn't know printf was builtin.  It wasn't years and years ago 
when I looked last.  But I'm sure bash has had two or three major 
versions since then. :)

>     Even better, put the whole thing into a subshell with ( ) and
>     redirect the output of it all at once.
> 
> 
> Using {} instead of () offers that benefit without the cost or 
> environment-shift of a subshell.   (Zan knows it won't much matter in 
> this case -- it's a one-shot -- but I still think it's worth a mention 
> for the less-frequent shell programmer.)

I don't think there is a cost to using () over {}.  From what I can 
tell, every pipeline is executed in a subshell just like a ().  I could 
be wrong though.

-- 
Zan Lynx
zlynx at acm.org

"Knowledge is Power.  Power Corrupts.  Study Hard.  Be Evil."



More information about the LUG mailing list