[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: alias does not match POSIX
From: |
Chet Ramey |
Subject: |
Re: alias does not match POSIX |
Date: |
Sat, 24 Apr 2004 17:25:36 -0400 |
User-agent: |
Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.6) Gecko/20040113 |
Eric Blake wrote:
Bash Version: 2.05b
Patch Level: 0
Release Status: release
Description:
I have the aliases xargs='xargs ' and grep='grep --color'. I wanted
to alias -0 so that I could do ``find . -print0 | xargs -0 grep foo''
and have the output colorized, when I ran into some counterintuitive
behavior. With further research, I have determined that the
processing of the shell builtin ``alias'' violates POSIX 2003. Refer
to http://www.opengroup.org/onlinepubs/007904975/utilities/alias.html.
Thanks for the consideration you've given this issue. You make
some good points.
First is the formatting of the output. Under STDOUT, POSIX requires
that "The format for displaying aliases (when no operands or only name
operands are specified) shall be:
"%s=%s\n", name, value
The value string shall be written with appropriate quoting so that it
is suitable for reinput to the shell."
Though I disagree with this, I have changed `posix mode' output to
match the standard for the next version.
Next, there are bash documentation issues. Bash does not document
what characters are legal as extensions in an alias name. POSIX
defines alias names:
Bash has never documented restrictions on which characters it
allows in alias names for the simple reason that it has never
placed any such restrictions.
It's probably a good idea, though, to restrict the set of alias
name characters, simply because, as you observe, characters which
need to be quoted to avoid special treatment by the shell parser
will not be eligible for alias expansion anyway.
The next version of bash will disallow shell metacharacters and
other characters which must be quoted to prevent special treatment
by the parser, and `$' and ``' (in addition to `/', of course).
The next documentation issue is the lack of mention that ``--'' can be
used on the alias builtin (and in fact, must be used to alias a non-POSIX
aliasname such as -0).
This is not correct. Read the first sentence in the SHELL BUILTIN
COMMANDS section of the manual page.
Another thing to worry about is the interaction between aliases and
history. Alias expansion is required by POSIX, history is not. And
alias names are required by POSIX to support !. Therefore, in the
second half of my example below, with POSIXLY_CORRECT, I would expect
the alias !a to be expanded, and output ``hi'', rather than history
expansion to occur.
This is why they are separate options. If you don't want history
expansion, disable it. Bash is perfectly happy to expand an alias
containing `!' when history expansion is not enabled.
One last thing - the POSIX specification for unalias states that
arguments are mandatory, but bash returns 0 on ``unalias'', without
changing the current set of aliases. You should document this valid
extension, and consider making unalias report an error if it is not
given arguments.
I have changed bash to report an error in this case.
Fortunately, I think your documented weakness that ``alias a=b; a''
invokes the command a rather than performing alias expansion and
invoking b is valid under POSIX
Imagine my relief.
Chet