Re: [BUG] Illegal function names are accepted after being used as aliases

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

 



On 23/02/2016 19:18, Jan Verbeek wrote:
Function definitions that use a bad function name (such as "-" and "=")
are accepted if the function name already exists as an alias. For example:

$ -
dash: 1: -: not found
$ - () { echo hello; }
dash: 2: Syntax error: Bad function name
$ -
dash: 2: -: not found
$ alias -=true
$ -
$ - () { echo hello; }
$ -
hello
$

After alias -=true, - () { echo hello; } is treated as a use of that alias. It doesn't define a function with a name of -, it defines a function with a name of true, which consists only of valid characters.

$ alias -=true
$ -() { echo hello; }
$ type -
- is an alias for true
$ type true
true is a shell function
$ true
hello

This matches bash's behaviour, aside from bash requiring -- to prevent detection of invalid flags to the alias command:

bash-4.3$ alias -- -=true
bash-4.3$ -() { echo hello; }
bash-4.3$ type -
- is aliased to `true'
bash-4.3$ type true
true is a function
true ()
{
    echo hello
}
bash-4.3$ true
hello

Cheers,
Harald van Dijk
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux