Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Two bug reports: alias/function disagreements; incorrect redirection
- X-seq: zsh-workers 16882
- From: Peter Stephenson <pws@xxxxxxx>
- To: David Hughes <David.W.Hughes@xxxxxxx>, zsh-workers@xxxxxxxxxx (Zsh hackers list)
- Subject: Re: Two bug reports: alias/function disagreements; incorrect redirection
- Date: Fri, 22 Mar 2002 12:41:50 +0000
- In-reply-to: "David Hughes"'s message of "Fri, 22 Mar 2002 13:24:40 +0100." <3C9B2288.5070304@xxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
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@xxxxxxx> 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.
**********************************************************************
Messages sorted by:
Reverse Date,
Date,
Thread,
Author