Aliases in subbshell does not work as expected

2009-01-11 Thread Коренберг Марк

Configuration Information [Automatically generated, do not change]:
Machine: i486
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALED $uname output: Linux mmarkk-desktop 
2.6.27-11-generic #1 SMP Thu Jan 8 08:38:33 UTC 2009 i686 GNU/Linux

Machine Type: i486-pc-linux-gnu

Bash Version: 3.2
Patch Level: 39
Release Status: release

Description:
   See Repeat-by section.

Repeat-By:
   alias aaa='echo aaa'; ( alias aaa='echo bbb'; aaa ; )
   Will print 'aaa' instead of 'bbb' as I expect.




Re: Aliases in subbshell does not work as expected

2009-01-11 Thread Jon Seymour
G'day,

This working as documented.

The relevant part of the manual is, I think:

Bash always reads at  least  one  complete  line  of  input  before
executing  any  of  the  commands  on  that  line.  Aliases are
expanded when a command is read, not when it is  executed.

If aaa is not already defined, the actual behaviour is:

$ alias aaa='echo aaa'; ( alias aaa='echo bbb'; aaa ; )
-bash: aaa: command not found

Which is consistent with the manual page. If aaa is already defined, then

$ alias aaa='echo aaa'; ( alias aaa='echo bbb'; aaa ; )
aaa

which is what you observed.

Use unalias aaa and then you will get:

$ alias aaa='echo aaa'; ( alias aaa='echo bbb'; aaa ; )
-bash: aaa: command not found

jon.

On 11/01/2009, at 23:18, Коренберг Марк
socketp...@gmail.com wrote:

 Configuration Information [Automatically generated, do not change]:
 Machine: i486
 OS: linux-gnu
 Compiler: gcc
 Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' -
 DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' -
 DCONF_VENDOR='pc' -DLOCALED $uname output: Linux mmarkk-desktop
 2.6.27-11-generic #1 SMP Thu Jan 8 08:38:33 UTC 2009 i686 GNU/Linux
 Machine Type: i486-pc-linux-gnu

 Bash Version: 3.2
 Patch Level: 39
 Release Status: release

 Description:
   See Repeat-by section.

 Repeat-By:
   alias aaa='echo aaa'; ( alias aaa='echo bbb'; aaa ; )
   Will print 'aaa' instead of 'bbb' as I expect.