Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Odd behavior using MULTIOS

Another thing I noticed is that MULTIOS doesn't appear to work with exec


exec 3>/tmp/test1 3>/tmp/test2

causes the script to hang.

I'm not sure why.  Am I just being dense today?

On 11/11/2020 10:42 AM, Peter Stephenson wrote:
On 11 November 2020 at 16:25 Clinton Bunch <cdb_zsh@xxxxxxxxxxx> wrote:
Is this the expected behavior?

setopt MULTIOS
print -u3 "Testing"
print  "Second Testing"
} 3>&1 3>/tmp/test
% zsh test.zsh
Second Testing
You mean the ordering?  Yes, as documented "the shell opens the file descriptor as a pipe
to  a process that copies its input to all the specified outputs".  So this isn't
synchronous within the current shell and you can't rely on ordering.  You'll note
there's nothing there to determine whether the downstream pipe component performs
a write to the terminal before the main shell does --- think of it a bit like

{ print Testing; print "Second Testing" >/dev/tty } | tee /dev/tty /tmp/test

--- although I'm not guaranteeing they're identical and clearly there's room
for lots of things in the two processes to affect the ordering.


Messages sorted by: Reverse Date, Date, Thread, Author