zsh-workers
 help / color / mirror / code / Atom feed
* I/O redirection problem in "zsh"
@ 2002-10-25 10:40 Matthias Scheler
  2002-10-25 11:13 ` Oliver Kiddle
  2002-10-25 11:16 ` Borzenkov Andrey
  0 siblings, 2 replies; 6+ messages in thread
From: Matthias Scheler @ 2002-10-25 10:40 UTC (permalink / raw)
  To: zsh-workers


	Hello,

the I/O redirection in the following command doesn't work properly in "zsh":

grep localhost /etc/hosts fasel 2>&1 >/dev/null | cat -b

tron@colwyn:~>grep localhost /etc/hosts fasel 2>&1 >/dev/null | cat -b
     1  grep: fasel: No such file or directory
     2  /etc/hosts:::1                                  localhost
     3  /etc/hosts:127.0.0.1                            localhost
tron@colwyn:~>sh
$ grep localhost /etc/hosts fasel 2>&1 >/dev/null | cat -b
     1  grep: fasel: No such file or directory
$ bash
bash-2.05$ grep localhost /etc/hosts fasel 2>&1 >/dev/null | cat -b
     1  grep: fasel: No such file or directory
bash-2.05$ ksh
$ grep localhost /etc/hosts fasel 2>&1 >/dev/null | cat -b
     1  grep: fasel: No such file or directory

I can reproduce this problem with ZSH 3.0.8 under Solaris and ZSH 4.0.6
under NetBSD.

	Kind regards

-- 
Matthias Scheler                                  http://scheler.de/~matthias/


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

* Re: I/O redirection problem in "zsh"
  2002-10-25 10:40 I/O redirection problem in "zsh" Matthias Scheler
@ 2002-10-25 11:13 ` Oliver Kiddle
  2002-10-25 11:16 ` Borzenkov Andrey
  1 sibling, 0 replies; 6+ messages in thread
From: Oliver Kiddle @ 2002-10-25 11:13 UTC (permalink / raw)
  To: Matthias Scheler; +Cc: zsh-workers

On 25 Oct, you wrote:
> 
> the I/O redirection in the following command doesn't work properly in "zsh":
> 
> grep localhost /etc/hosts fasel 2>&1 >/dev/null | cat -b
> 
> tron@colwyn:~>grep localhost /etc/hosts fasel 2>&1 >/dev/null | cat -b
>      1  grep: fasel: No such file or directory
>      2  /etc/hosts:::1                                  localhost
>      3  /etc/hosts:127.0.0.1                            localhost

This is an effect of the multios option. If you do an unsetopt multios,
it will work the same as in sh. Multios allows shorthands for the tee
command so the output above is sent to both /dev/null and the pipe which
you can see if you use a file instead of /dev/null.

Oliver

This e-mail and any attachment is for authorised use by the intended recipient(s) only.  It may contain proprietary material, confidential information and/or be subject to legal privilege.  It should not be copied, disclosed to, retained or used by, any other party.  If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender.  Thank you.


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

* RE: I/O redirection problem in "zsh"
  2002-10-25 10:40 I/O redirection problem in "zsh" Matthias Scheler
  2002-10-25 11:13 ` Oliver Kiddle
@ 2002-10-25 11:16 ` Borzenkov Andrey
  2002-10-25 11:44   ` Matthias Scheler
  1 sibling, 1 reply; 6+ messages in thread
From: Borzenkov Andrey @ 2002-10-25 11:16 UTC (permalink / raw)
  To: 'Matthias Scheler', zsh-workers


> 
> 	Hello,
> 
> the I/O redirection in the following command doesn't work properly in
> "zsh":
> 
> grep localhost /etc/hosts fasel 2>&1 >/dev/null | cat -b
> 
> tron@colwyn:~>grep localhost /etc/hosts fasel 2>&1 >/dev/null | cat -b
>      1  grep: fasel: No such file or directory
>      2  /etc/hosts:::1                                  localhost
>      3  /etc/hosts:127.0.0.1                            localhost
> tron@colwyn:~>sh
> $ grep localhost /etc/hosts fasel 2>&1 >/dev/null | cat -b
>      1  grep: fasel: No such file or directory
> $ bash
> bash-2.05$ grep localhost /etc/hosts fasel 2>&1 >/dev/null | cat -b
>      1  grep: fasel: No such file or directory
> bash-2.05$ ksh
> $ grep localhost /etc/hosts fasel 2>&1 >/dev/null | cat -b
>      1  grep: fasel: No such file or directory
> 
> I can reproduce this problem with ZSH 3.0.8 under Solaris and ZSH
4.0.6
> under NetBSD.
> 

This ambiguous. Both > and | mean redirection of stdout. Now, Zsh first
does redirections and then applies pipeline (which effectively reopens
stdout) and other shells first apply pipeline and then (inside of simple
command) do redirections. The following from SUS  makes me believe Zsh
is more correct:

"The standard output of command1 shall be connected to the standard
input of command2. The standard input, standard output, or both of a
command shall be considered to be assigned by the pipeline before any
redirection specified by redirection operators that are part of the
command (see Redirection )."

What other shells effectively do is to pipeline stderr not stdout.
Still I do not fully understand this sentence so I am not sure if my
interpretation is correct.

-andrey


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

* Re: I/O redirection problem in "zsh"
  2002-10-25 11:16 ` Borzenkov Andrey
@ 2002-10-25 11:44   ` Matthias Scheler
  2002-10-25 12:15     ` Oliver Kiddle
  2002-11-06 10:10     ` Zefram
  0 siblings, 2 replies; 6+ messages in thread
From: Matthias Scheler @ 2002-10-25 11:44 UTC (permalink / raw)
  To: Borzenkov Andrey; +Cc: zsh-workers

On Fri, Oct 25, 2002 at 03:16:13PM +0400, Borzenkov Andrey wrote:
> This ambiguous. Both > and | mean redirection of stdout.

Is there a better portable way to redirect stderr to the pipe but
ignore stdout?

	Kind regards

-- 
Matthias Scheler                                  http://scheler.de/~matthias/


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

* Re: I/O redirection problem in "zsh"
  2002-10-25 11:44   ` Matthias Scheler
@ 2002-10-25 12:15     ` Oliver Kiddle
  2002-11-06 10:10     ` Zefram
  1 sibling, 0 replies; 6+ messages in thread
From: Oliver Kiddle @ 2002-10-25 12:15 UTC (permalink / raw)
  To: Matthias Scheler; +Cc: zsh-workers

On Fri, Oct 25, 2002 at 01:44:52PM +0200, Matthias Scheler wrote:
> On Fri, Oct 25, 2002 at 03:16:13PM +0400, Borzenkov Andrey wrote:
> > This ambiguous. Both > and | mean redirection of stdout.
> 
> Is there a better portable way to redirect stderr to the pipe but
> ignore stdout?

I can't actually think of a way. Anyone else? If you are trying to
write a portable script, note that zsh will unset the multios
option when told to emulate sh.

If there isn't a way, perhaps we should make it so that:

  grep localhost /etc/hosts fasel 2>&1 1>/dev/null | cat -b
is different from
  grep localhost /etc/hosts fasel 2>&1 >/dev/null | cat -b

with the 1 causing it to move file-descriptor 1 instead of adding
another output for the pseudo-tee process.

Oliver

This e-mail and any attachment is for authorised use by the intended recipient(s) only.  It may contain proprietary material, confidential information and/or be subject to legal privilege.  It should not be copied, disclosed to, retained or used by, any other party.  If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender.  Thank you.


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

* Re: I/O redirection problem in "zsh"
  2002-10-25 11:44   ` Matthias Scheler
  2002-10-25 12:15     ` Oliver Kiddle
@ 2002-11-06 10:10     ` Zefram
  1 sibling, 0 replies; 6+ messages in thread
From: Zefram @ 2002-11-06 10:10 UTC (permalink / raw)
  To: Matthias Scheler; +Cc: Borzenkov Andrey, zsh-workers

Matthias Scheler wrote:
>Is there a better portable way to redirect stderr to the pipe but
>ignore stdout?

	{ command... 2>&1 >/dev/null; } | another-command...

Brace grouping effectively stops multios being accumulated, so later
redirections have their normal non-multio effect.  There's also

	command... 2>>( another-command... ) >/dev/null

-zefram


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

end of thread, other threads:[~2002-11-06 10:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-25 10:40 I/O redirection problem in "zsh" Matthias Scheler
2002-10-25 11:13 ` Oliver Kiddle
2002-10-25 11:16 ` Borzenkov Andrey
2002-10-25 11:44   ` Matthias Scheler
2002-10-25 12:15     ` Oliver Kiddle
2002-11-06 10:10     ` Zefram

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