[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mixing exec redirection with explicit redirection, unexpected result

From: Chet Ramey
Subject: Re: Mixing exec redirection with explicit redirection, unexpected results
Date: Tue, 08 Dec 2009 23:11:01 -0500
User-agent: Thunderbird (Macintosh/20090812)

address@hidden wrote:

>       When I use the 'exec' built-in to redirect standard output 
>       for a script, and then also use explicit redirection on 
>       other commands, pointing both to the same output file, 
>       I get unpredictable (but repeatable) results with the output 
>       out of order.
> Repeat-By:
>       The following script:
> #!/bin/bash
>> /tmp/foo
> exec 1>/tmp/foo
> echo a
> echo B >>/tmp/foo
> echo c
> echo D >>/tmp/foo
> echo e
> echo F >>/tmp/foo
> ...should produce the following contents in /tmp/foo:
> a
> B
> c
> D
> e
> F
> ...but instead it produces:
> a
> c
> e
> F
> Fix:
>       I am at a loss for how to understand this behavior -- sorry, 
>       I can't suggest a fix. :-(

It's not a bug.  The important thing to remember is that the appends,
since they use a new file descriptor with a separate file offset, don't
affect the file offset associated with fd 1.  Each subsequent echo
to fd 1 overwrites the previous echo that used an explicit append.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]