help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Glob star pattern does not match files beginning with a


From: Michael Convey
Subject: Re: [Help-bash] Glob star pattern does not match files beginning with a period
Date: Fri, 24 Jul 2015 08:18:50 -0700

On Mon, Jul 20, 2015 at 10:35 PM, Stephane Chazelas <
address@hidden> wrote:

>
> That should be:
>
> ls -d -- * .[!.]* ..?*


Fascinating! I've never seen '--' used in this way before (admitting my
inexperience). 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. Is convention
universal for all Linux commands? If so, is this documented
​ somewhere​
for non-builtin commands?


reply via email to

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