[Top][All Lists]

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

Re: function invoking alias fails if defined in same conditional

From: Eric Blake
Subject: Re: function invoking alias fails if defined in same conditional
Date: Sat, 17 Mar 2012 06:09:52 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1

On 03/16/2012 02:56 PM, gregrwm wrote:
> a function invoking an alias works, unless they are defined within the same 
> conditional, eg:

Thanks for the report, but this is not a bug.  Remember, aliases affect
parsing, so they can only be expanded during the parsing phase.  But
bash has to parse until the end of a compound command before it can do
any action within the command.  In that sense, 'alias' is exactly like
'set -v' just recently discussed here:

> $ if true;then
>>    alias aseparate='echo aseparate'
>> fi
> $ if true;then
>>          fseparate    ()(aseparate)
>> fi

Bash parsed two commands, so the parse of the second command was done
with the alias expansion of the first command in effect.

> $ if true;then
>>    alias atogether='echo atogether'
>>          ftogether    ()(atogether)
>> fi

Here, bash parses the entire compound command, then starts executing it.
 At the time of the parse, ftogether() was declared without any extra
meaning for atogether.

> $ aseparate
> aseparate
> $ fseparate
> aseparate
> $ atogether
> atogether
> $ ftogether
> bash: atogether: command not found

This behavior is expected, and not a bug.

Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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