r...@enterprise.herff-jones.com 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. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/