zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: David Hughes <David.W.Hughes@cern.ch>,
	zsh-workers@sunsite.dk (Zsh hackers list)
Subject: Re: Two bug reports: alias/function disagreements; incorrect redirection
Date: Fri, 22 Mar 2002 12:41:50 +0000	[thread overview]
Message-ID: <29631.1016800910@csr.com> (raw)
In-Reply-To: "David Hughes"'s message of "Fri, 22 Mar 2002 13:24:40 +0100." <3C9B2288.5070304@cern.ch>

David Hughes wrote:
> Bug I
> =====
> 
> Bad Things happen if I assign a name to an alias and then to a function.
> 
>      $ which echo
>      echo: shell built-in command
>      $ alias foo='echo bar'
>      $ foo () { echo baz }
>      $ which echo
>      echo () {
>              echo baz
>      }
> 
> Of course Very Bad Things now happen if I try to use `echo' or `foo'.

This is inconvenient but is already mentioned in the FAQ
(http://zsh.sunsite.dk/FAQ/), section 2.3.

  There is one other serious problem with aliases: consider 

      alias l='/bin/ls -F'
      l() { /bin/ls -la "$@" | more }

  l in the function definition is in command position and is expanded as
  an alias, defining /bin/ls and -F as functions which call /bin/ls, which
  gets a bit recursive. This can be avoided if you use function to define
  a function, which doesn't expand aliases. It is possible to argue for
  extra warnings somewhere in this mess. Luckily, it is not possible to
  define function as an alias.

(The last sentence is a lie, unfortunately, and I must get around to
changing it.)

> Bug II
> ======
> 
>      $ /bin/sh -c 'echo out; echo err >&2' 2>&1 >/dev/null
>      err
>      $ /bin/sh -c 'echo out; echo err >&2' 2>&1 >/dev/null | cat
>      err
>      out

This is not a bug, and if you are in sh-compatibility mode it doesn't
happen.  From the FAQ again,

  3.26: Why is my output duplicated with `foo 2>&1 >foo.out | bar'?

  This is a slightly unexpected effect of the option MULTIOS, which is set
  by default. Let's look more closely:

      foo 2>&1 >foo.out | bar

  What you're probably expecting is that the command foo sends its
  standard output to the pipe and so to the input of the command bar,
  while it sends its standard error to the file foo.out. What you actually
  see is that the output is going both to the pipe and into the file. To
  be more explicit, here's the same example with real commands:

      % { print output; print error >&2 } 2>&1 >foo.out | sed 's/error/erratic'
      erratic
      output
      % cat foo.out
      output

  and you can see `output' appears twice.

  It becomes clearer what's going on if we write: 

      % print output >foo1.out >foo2.out
      % cat foo1.out
      output
      % cat foo2.out
      output

  You might recognise this as a standard feature of zsh, called `multios'
  and controlled by the option of the same name, whereby output is copied
  to both files when the redirector appears twice. What's going on in the
  first example is exactly the same, however the second redirector is
  disguised as a pipe. So if you want to turn this effect off, you need to
  unset the option MULTIOS.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


  reply	other threads:[~2002-03-22 12:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-22 12:24 David Hughes
2002-03-22 12:41 ` Peter Stephenson [this message]
2002-03-23 21:18   ` Piping stderr (was Re: Two bug reports) Wayne Davison
2002-03-23 22:45     ` Bart Schaefer
2002-03-23 23:47       ` Multios again (Re: Piping stderr (was Re: Two bug reports)) Bart Schaefer
2002-03-24  9:01       ` Piping stderr (was Re: Two bug reports) Wayne Davison
2002-03-24 16:47         ` Borsenkow Andrej
2002-03-24 19:02           ` Bart Schaefer
2002-03-24 19:09             ` Bart Schaefer
2002-03-24 19:50             ` PATCH: (Doc) " Bart Schaefer
2002-03-25  0:17             ` Wayne Davison

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=29631.1016800910@csr.com \
    --to=pws@csr.com \
    --cc=David.W.Hughes@cern.ch \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).