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

Re: multios doesn't work with 2>&1

On Oct 27, 10:59pm, Han Pingtian wrote:
} According to the zsh guide's "2.5.8 `Go faster' options for power
} users", page 44:
}     % echo foo 2>&1 >/dev/null | sed 's/foo/bar/'
} should output "bar" if multios has been set. But it outputs nothing

Hmm, looks like this has been broken for a LONG time.

If I back out workers/20666 (Jan 2005), then this example works again.

Note that

    % print -u2 foo 2>&1 >/dev/null | sed 's/foo/bar/'

does print "bar", so the problem is that the original fd 1 is directed
to /dev/null while the multio fd created by 2>&1 is is directed to the
pipe.  You can see the reasoning for this in the "references" thread
going back from http://www.zsh.org/mla/workers/2005/msg00026.html

The workaround is to either explicitly add the original stdout to the

    % echo foo 2>&1 >&1 >/dev/null | sed 's/foo/bar/'

Or to make sure the multio isn't created until the pipe is seen:

    % { echo foo 2>&1 } >/dev/null | sed 's/foo/bar/'

If there's a way to fix the original complaint (that >&- doesn't really
close the descriptor when a multio is involved, so unnecessary multios
result) without the above example remaining broken, I may need some help
to find it.

Otherwise we have to decide whether to revert to the pre-2005 behavior,
or document around it.

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