bug-bash
[Top][All Lists]
Advanced

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

Re: embraced redefinition of aliases and function causes endless recursi


From: Chet Ramey
Subject: Re: embraced redefinition of aliases and function causes endless recursion
Date: Mon, 15 Apr 2002 12:17:47 -0400

> Machine Type: sparc-sun-solaris2.7
> 
> Bash Version: 2.05a
> Patch Level: 0
> Release Status: release
> 
> Description:
>         Consider an alias is calling a function and the function
>         calls an executable, function or bultin.
>         (The alias is used to wrap only the interactive call of the function.)
>         Then bash goes into endless recursion, if the alias is declared
>         before and after the function OR the function is declared before
>         and after the alias.
>         A embraced redefinition always happens, if the .bashrc is
>         sourced again.
> 
> Repeat-By:
>         alias cd=cda
>         function cda() { cd "$@"; }
>         alias cd=cda
>         cd /

You've created a recursive function.  Function definitions themselves are
compound commands.  Alias expansion is performed while parsing the function
definition.  You end up with this function:

        function cda() { cda "$@"; }

The implications should be clear.

You can change things to do what you want by using the `builtin' command
in the function definition.  You don't need the alias at all, in fact.

        cd() { builtin cd "$@"; }

You could also quote the cd in the function definition.


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)

Chet Ramey, CWRU    chet@po.CWRU.Edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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