zsh-users
 help / color / mirror / code / Atom feed
* multios doesn't work with 2>&1
@ 2013-10-27 14:59 Han Pingtian
  2013-10-27 17:01 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Han Pingtian @ 2013-10-27 14:59 UTC (permalink / raw)
  To: zsh-users

Hello,

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
here. But if I removed the "2>&1", then it works just fine:

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

Please have a look. Thanks.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: multios doesn't work with 2>&1
  2013-10-27 14:59 multios doesn't work with 2>&1 Han Pingtian
@ 2013-10-27 17:01 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2013-10-27 17:01 UTC (permalink / raw)
  To: zsh-users

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
multio: 

    % 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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-10-27 17:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-27 14:59 multios doesn't work with 2>&1 Han Pingtian
2013-10-27 17:01 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).