zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: Huy Le <huyle@xeno.ugcs.caltech.edu>, zsh-workers@math.gatech.edu
Subject: Re: zsh3.0.0 bug: aliases in if-statement
Date: Tue, 1 Oct 1996 17:34:20 -0700	[thread overview]
Message-ID: <961001173420.ZM24672@candle.brasslantern.com> (raw)
In-Reply-To: Huy Le <huyle@xeno.ugcs.caltech.edu> "zsh3.0.0 bug: aliases in if-statement" (Oct  1,  4:51pm)

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.


  reply	other threads:[~1996-10-02  0:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-10-01 23:51 Huy Le
1996-10-02  0:34 ` Bart Schaefer [this message]
1996-10-02 10:55   ` Peter Stephenson
1996-10-02 12:02     ` Zoltan Hidvegi

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=961001173420.ZM24672@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=huyle@xeno.ugcs.caltech.edu \
    --cc=schaefer@nbn.com \
    --cc=zsh-workers@math.gatech.edu \
    /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).