From: Harald van Dijk <harald@gigawatt.nl>
To: Jan Verbeek <ring@openmailbox.org>, dash@vger.kernel.org
Subject: Re: [BUG] Illegal function names are accepted after being used as aliases
Date: Tue, 23 Feb 2016 19:44:09 +0100 [thread overview]
Message-ID: <56CCA879.1070208@gigawatt.nl> (raw)
In-Reply-To: <56CCA25E.5020809@openmailbox.org>
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
next prev parent reply other threads:[~2016-02-23 18:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-23 18:18 [BUG] Illegal function names are accepted after being used as aliases Jan Verbeek
2016-02-23 18:40 ` Eric Blake
2016-02-23 18:44 ` Harald van Dijk [this message]
2016-02-23 18:58 ` Eric Blake
2016-02-23 19:21 ` Harald van Dijk
2016-02-23 19:33 ` Eric Blake
2016-02-23 21:00 ` Harald van Dijk
2016-02-23 21:49 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56CCA879.1070208@gigawatt.nl \
--to=harald@gigawatt.nl \
--cc=dash@vger.kernel.org \
--cc=ring@openmailbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox