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

Sam Steingold<s...@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   ebl...@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Reply via email to