zsh-workers
 help / color / mirror / code / Atom feed
* zsh3.0.0 bug: aliases in if-statement
@ 1996-10-01 23:51 Huy Le
  1996-10-02  0:34 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Huy Le @ 1996-10-01 23:51 UTC (permalink / raw)
  To: zsh-workers

HP-UX, IRIX, SunOS, ...

unalias a b 2>/dev/null
alias a=cat
if true; then
  alias b=cat
  works() { echo yes | a }
  fails() { echo yes | b }
fi
works2() { echo yes | b }


(Kinda reminiscent of csh for some reason.)
The same applies if you replace the if-statement with a case-statement.

    -Huy


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

* Re: zsh3.0.0 bug: aliases in if-statement
  1996-10-01 23:51 zsh3.0.0 bug: aliases in if-statement Huy Le
@ 1996-10-02  0:34 ` Bart Schaefer
  1996-10-02 10:55   ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 1996-10-02  0:34 UTC (permalink / raw)
  To: Huy Le, zsh-workers

On Oct 1,  4:51pm, Huy Le wrote:
> Subject: zsh3.0.0 bug: aliases in if-statement
> 
> unalias a b 2>/dev/null
> alias a=cat
> if true; then
>   alias b=cat
>   works() { echo yes | a }
>   fails() { echo yes | b }
> fi
> works2() { echo yes | b }

I've been complaining about this for ages.  The problem is that zsh
parses and completely tokenizes the whole "if" statement before it
executes any of it.  Thus the textual replacement of "cat" for "b"
in the fails() function, can't happen, because "b" is already a token
rather than a string subject to alias expansion.

Your example is just a more subtle variant of:

fails2() { echo yes | foo }
alias foo=cat

The workaround, of course, is either:

if true; then
  alias b=cat
  works() { echo yes | a }
  eval 'worksToo() { echo yes | b }'
fi

or:

if true; then
  alias b=cat
  works() { echo yes | a }
  worksToo() { echo yes | eval b }
fi

IMHO, alias expansion has always happened too soon in zsh, but it greatly
complicates matters to go around reshaping syntax trees at execution time.


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

* Re: zsh3.0.0 bug: aliases in if-statement
  1996-10-02  0:34 ` Bart Schaefer
@ 1996-10-02 10:55   ` Peter Stephenson
  1996-10-02 12:02     ` Zoltan Hidvegi
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 1996-10-02 10:55 UTC (permalink / raw)
  To: Zsh hackers list

"Bart Schaefer" wrote:
> IMHO, alias expansion has always happened too soon in zsh, but it greatly
> complicates matters to go around reshaping syntax trees at execution time.

Not just too soon, I've often thought, but too much.  I don't like the
following at all.

% which ls
ls: aliased to ls -F
% foo() { command ls }
% which foo
foo () {
        command ls -F
}

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.


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

* Re: zsh3.0.0 bug: aliases in if-statement
  1996-10-02 10:55   ` Peter Stephenson
@ 1996-10-02 12:02     ` Zoltan Hidvegi
  0 siblings, 0 replies; 4+ messages in thread
From: Zoltan Hidvegi @ 1996-10-02 12:02 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

Peter Stephenson wrote:
> "Bart Schaefer" wrote:
> > IMHO, alias expansion has always happened too soon in zsh, but it greatly
> > complicates matters to go around reshaping syntax trees at execution time.
> 
> Not just too soon, I've often thought, but too much.  I don't like the
> following at all.
> 
> % which ls
> ls: aliased to ls -F
> % foo() { command ls }
> % which foo
> foo () {
>         command ls -F
> }

bash, ksh and pdksh behaves similarily.  Aliases should be thought as
macros which expand during compile time.  That's especially true for global
aliases.  Shell functions can do almost anything that a non-global alias
can.  Adding special checks for aliases in the body of comblex commands
would require reparsing of the body which would make zsh much slower and
the code would become more compicated.  POSIX omitted aliases because shell
functions have much more clear semantics and provide more functionality
than aliases and they are even more portable than aliases.

Zoltan


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

end of thread, other threads:[~1996-10-02 12:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-10-01 23:51 zsh3.0.0 bug: aliases in if-statement Huy Le
1996-10-02  0:34 ` Bart Schaefer
1996-10-02 10:55   ` Peter Stephenson
1996-10-02 12:02     ` Zoltan Hidvegi

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