On Fri, Jul 31, 2015 at 2:12 PM, Eli Zaretskii <[email protected]> wrote:

> > From: Michael Convey <[email protected]>
> > Date: Fri, 31 Jul 2015 11:59:43 -0700
> > Cc: "[email protected]" <[email protected]>
> >
> > ​$ info -- apropos ​
> > ​\'\-\-\'
> > info: No available info files have ''--'' in their indices.
>
> Why in the world would you want to look for that?  What stuff did you
> _really_ want to find?
>

I was trying to determine how universal '--' is for delimiting the option
list. In other words, does this argument signal the end of options and
disable further option processing universally, or only for bash builtins?


​According to POSIX:

Default Behavior: When this section is listed as "None.", it means that the
implementation need not support any options. Standard utilities that do not
accept options, but that do accept operands, shall recognize "--" as a
first argument to be discarded.
​ ​
The requirement for recognizing "--" is because conforming applications
need a way to shield their operands from any arbitrary options that the
implementation may provide as an extension. For example, if the standard
utility foo is listed as taking no options, and the application needed to
give it a pathname with a leading <hyphen>, it could safely do it as:
​ '
foo -- -myfile
​'
and avoid any problems with -m used as an extension.

According to the man page for any of the bash builtin commands:

Unless otherwise noted, each builtin command documented as accepting
options preceded by ‘-’ accepts ‘--’ to signify the end of the options. The
:, true, false, and test builtins do not accept options and do not treat
‘--’ specially. The exit, logout, break, continue, let, and shift builtins
accept and process arguments beginning with ‘-’ without requiring ‘--’.
Other builtins that accept arguments but are not specified as accepting
options interpret arguments beginning with ‘-’ as invalid options and
require ‘--’ to prevent this interpretation.

In the man pages, I could not find any other instances of this use of '--'
to signify the end of the options. Therefore, only bash builtin command man
page explicitly state that they follow this convention. According to 'type
ls', this command is not a bash builtin; so how do we know this convention
works? We can prove that it does by testing
​ it​
, as follows:

$ ls -Ap
.a ...barfoo ..foobar -i/
$ ls -dAp * .[!.] ..?*
289308 .a 289297 ...barfoo 272356 ..foobar
$ ls -dAp -- * .[!.] ..?*
.a ...barfoo ..foobar -i/

However, I wouldn't want to test this for every command. So, I searched all
info nodes to determine how universal '--' for disable further option
processing. I turns out, it's pretty universal.

Without
zgrep /usr/share/info/*
​​
\'\-\-\'
I couldn't have determined that.

Reply via email to