[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Mixing exec redirection with explicit redirection, unexpected result
Re: Mixing exec redirection with explicit redirection, unexpected results
Tue, 08 Dec 2009 18:58:02 -0800
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:188.8.131.52pre) Gecko/20091014 Fedora/3.0-2.8.b4.fc11 Thunderbird/3.0b4
That script creates two simultaneous writers of /tmp/foo
(one via the "exec >", another via each "echo >>")
but does not provide any concurrency control.
Shame on the script; the results are undefined.
The only possible legitimate complaint _might_ be
that bash did not detect and warn about the user error.
The fix is to provide some concurrency control,
or not to create multiple simultaneous writers of the same file.
Because all output is going to the same file, then the simplest
solution is to omit all the appending ">>/tmp/foo" because
they are subsumed by the initial redirection "exec >/tmp/foo".
Perhaps concurrency control can be provided by using a fifo:
cp /tmp/my_fifo /tmp/foo & # constantly drain the fifo
echo B >>/tmp/my_fifo
etc. However, this relies upon bash _not_ buffering
the first redirection, and that is not guaranteed.
Bottom line: avoid simultaneous writers of the same file.