bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: conditional aliases are broken


From: Eric Blake
Subject: Re: conditional aliases are broken
Date: Mon, 15 Aug 2011 13:49:31 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.11

On 08/15/2011 01:10 PM, Sam Steingold wrote:
* Andreas Schwab<fpujno@yvahk-z68x.bet>  [2011-08-15 18:42:30 +0200]:

Sam Steingold<sds@gnu.org>  writes:

this works:

$ alias z='echo a'
$ zz(){ z b; }
$ zz
a b

however, after sourcing this file:
if true; then
   alias z='echo a'
   zz(){ z b; }
fi

Aliases are expanded during reading, but the alias command isn't
executed until after the complete compound command was read.

Cool.  Now, what does this imply?
Is this the expected behavior aka "feature"?

Yep - feature. All shells behave that way. They parse to an end of a command (in your case, the end of the compound 'if-fi' command), then process statements within the command. Alias expansion affects parsing, so your alias cannot take effect until after the compound command has been parsed, and all attempts to use the alias from within the compound command were parsed with the pre-command expansion (ie. no alias).

Yet another reasons why aliases are mostly replaced by functions.

--
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]