[clug] Next in my series of "how to do things in /bin/sh that you probably shouldn't".

Kevin Pulo kev at pulo.com.au
Wed Aug 19 19:02:30 MDT 2009


On Thu, Aug 20, 2009 at 10:39:53AM +1000, Andrew Janke wrote:

> Suppose that I want to send all output from a shell script to a
> logfile as well as displaying it (within the script). To simply send
> everything in a shell script I can just do this somewhere near the top
> of the script:
> 
>    exec > logfile.txt 2>&1
> 
> But I am greedy, as such it is a pity you can't just do this:
> 
>    exec | tee logfile 2>&1

Not that I've tried it, but using process substitution to get bash to
automatically do the pipe magic might work?

    exec > >(tee logfile.txt) 2>&1

Kev.

-- 
.----------------------------------------------------------------------.
| Kevin Pulo                Quidquid latine dictum sit, altum viditur. |
| kev at pulo.com.au               _ll l_ng__g_e_ _r_ hi__ly p__d_ct__le. |
| http://www.kev.pulo.com.au/         God casts the die, not the dice. |
`--------------- Linux: The choice of a GNU generation. ---------------'
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/linux/attachments/20090820/541c6532/attachment.pgp>


More information about the linux mailing list