17.11.2024 20:27, Kirill A. Korinsky пишет:
> On Sun, 17 Nov 2024 17:52:26 +0100,
> Jeremie Courreges-Anglas <j...@wxcvbn.org> wrote:
>>
>> See main.c:
>>          /* Aliases that are builtin commands in at&t */
>>        "login=exec login",
>>
>> I guess a builtin would be slightly cleaner, but it means more code.
>>
> 
> Indeed, the bug can be reproduced only when I use a builtin alias which has
> space in it's definition:

The problem is defining a function with the same name as an alias that expands
to more than one word, just containing a space is not enough:

        $ alias nohup r
        nohup='nohup '
        r='fc -s'
        $ nohup() {}
        $ r() {}
        sh: syntax error: `(' unexpected

I can't say right away what the shell is supposed to do here and/or what it
really does;  looks like it expands the alias and before function definition.

'unalias r' works only interative shells:

        $ unalias r
        $ r() {}
        $ type r
        r is a function

        $ sh -c 'unalias r; r() {}'
        sh: syntax error: `(' unexpected

You can also escape the function name instead, but then the alias still
takes precedence:

        $ type r
        r is an alias for 'fc -s'
        $ \r() {}
        $ type r
        r is an alias for 'fc -s'


> 
>         ksh $ echo 'integer() { }' | ksh -n -       
>         ksh: <stdin>[1]: syntax error: `(' unexpected
>         ksh $ echo 'nohup() { }' | ksh -n -         
>         ksh $ echo 'history() { }' | ksh -n -
>         ksh: <stdin>[1]: syntax error: `(' unexpected
>         ksh $ echo 'local() { }' | ksh -n -   
>         ksh $
> 

Reply via email to