bug-bash
[Top][All Lists]
Advanced

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

Re: Issues when func name is the same with an alias


From: Bernd Eggink
Subject: Re: Issues when func name is the same with an alias
Date: Wed, 04 Aug 2010 14:27:09 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.2.7) Gecko/20100713 Thunderbird/3.1.1

Am 04.08.2010 12:39, schrieb Clark J. Wang:
I was testing the precedence between functions and aliases so I tried like
this (with bash 4.1.5):

$ cat rc
alias foo='echo this is the alias'

foo()
{
     builtin echo 'this is the function'
}

foo
$ source rc
bash: confusing-aliases-2.sh: line 4: syntax error near unexpected token `('
bash: confusing-aliases-2.sh: line 4: `foo()'
$

Seems like I must explicitly use the `function' keyword to define foo() for
this scenario. Is that the correct behavior?

The man page says "The first word of a simple command, if unquoted, is checked to see if has an alias". Therefore 'foo' in your function declaration is replaced by 'echo this is the alias'. Unfortunately, you can't quote the function name in the declaration, so you have to either use 'function' or say "unalias foo" first.

Regards,
Bernd

--
Bernd Eggink
http://sudrala.de



reply via email to

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