From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by coral.primenet.com.au (8.7.5/8.7.3) with ESMTP id KAA04241 for ; Wed, 2 Oct 1996 10:37:52 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id UAA01284; Tue, 1 Oct 1996 20:31:39 -0400 (EDT) Resent-Date: Tue, 1 Oct 1996 20:31:39 -0400 (EDT) From: "Bart Schaefer" Message-Id: <961001173420.ZM24672@candle.brasslantern.com> Date: Tue, 1 Oct 1996 17:34:20 -0700 In-Reply-To: Huy Le "zsh3.0.0 bug: aliases in if-statement" (Oct 1, 4:51pm) References: <199610012351.QAA09318@envy.ugcs.caltech.edu> Reply-To: schaefer@nbn.com X-Mailer: Z-Mail (4.0b.820 20aug96) To: Huy Le , zsh-workers@math.gatech.edu Subject: Re: zsh3.0.0 bug: aliases in if-statement MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"lSHso2.0.-J.gVRKo"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/2185 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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.