Re: Always use "--" (Was: Long filenames in DOS/Windows and Unix/Linux)

Liste des GroupesRevenir à cu programmer 
Sujet : Re: Always use "--" (Was: Long filenames in DOS/Windows and Unix/Linux)
De : lew.pitcher (at) *nospam* digitalfreehold.ca (Lew Pitcher)
Groupes : comp.unix.programmer
Date : 05. Sep 2024, 15:48:31
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vbcgbu$cc45$1@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2)
On Thu, 05 Sep 2024 02:29:49 +0000, Kaz Kylheku wrote:

On 2024-09-04, Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
On Wed, 04 Sep 2024 13:04:07 +0000, Kenny McCormack wrote:
>
In article <vb9k2l$3r705$1@dont-email.me>,
Nuno Silva  <nunojsilva@invalid.invalid> wrote:
...
D'oh!
>
(Along with these quotes, I'd add ./ before $file.)
 
Or, more simply, just put -- after the -p.
 
This is an often overlooked aspect of shell programing.  You should always
use "--".  The "shellcheck" program will tell you this, if you let it.
>
The "--" option is just that, an option coded into the argument parser of
the program being invoked. Many programs /do not/ recognize "--" as an
"end of flags" argument, so the effectiveness of "--" is unreliable.
>
OTOH, if you specify a fully qualified pathname, (or, at least, a qualified
relative pathname), you can assure yourself that the file path provided
to the program /will not/ start with the '-' that indicates a program flag.
>
Note that all this is /convention/ and not /requirement/. There are situations
in which /none/ of the above applies, as
a) the program interprets it's arguments by /position/, or
b) the program doesn't use the '-' to introduce flag arguments, or
c) the program doesn't take filenames as arguments, or
d) some other conditions that I'm too lazy to enumerate
 
d) it's a goddamned GNU program that continues to take options
after non-option arguments!
 
$ ls . -ld
drwxr-xr-x 67 kaz kaz 36864 Sep  3 15:59 .
 
... unless -- is specified to signal the end of options.
 
$ ls -ld -- . -ld
ls: cannot access '-ld': No such file or directory
drwxr-xr-x 67 kaz kaz 36864 Sep  3 15:59 .
 
So unfortunately although starting an argument with ./ will
ensure that it's not treated as an option, it doesn't mean
it will be treated as the first non-option argument after
which there are no more option arguments.

That seems to be a symptom of the use of the GNU variant of
the POSIX getopt(3) function.
  "By default, [GNU] getopt() permutes the contents of argv as it scans, so that
   eventually all the nonoptions are at the end.  Two other modes are also
   implemented.   If  the first character of optstring is '+' or the envi-
   ronment variable POSIXLY_CORRECT is set, then option  processing  stops
   as soon as a nonoption argument is encountered."

The "workaround" seems to be to set the POSIXLY_CORRECT envvar as part of
your standard environment.

--
Lew Pitcher
"In Skills We Trust"

Date Sujet#  Auteur
31 Aug 24 * Long filenames in DOS/Windows and Unix/Linux (Was: Piping to stdin)61Kenny McCormack
31 Aug 24 +* Re: Long filenames in DOS/Windows and Unix/Linux11Richard Kettlewell
31 Aug 24 i+- Re: Long filenames in DOS/Windows and Unix/Linux1Muttley
1 Sep 24 i`* Re: Long filenames in DOS/Windows and Unix/Linux9Lawrence D'Oliveiro
1 Sep 24 i +* Re: Long filenames in DOS/Windows and Unix/Linux7Lawrence D'Oliveiro
1 Sep 24 i i+- Re: Long filenames in DOS/Windows and Unix/Linux1Nuno Silva
1 Sep 24 i i+- Re: Long filenames in DOS/Windows and Unix/Linux1Helmut Waitzmann
1 Sep 24 i i+- Putting arbitrary characters into the shell command line (was: Long filenames in DOS/Windows and Unix/Linux)1Helmut Waitzmann
3 Sep 24 i i+* Re: Long filenames in DOS/Windows and Unix/Linux2Wayne
3 Sep 24 i ii`- Re: Long filenames in DOS/Windows and Unix/Linux1Lawrence D'Oliveiro
8 Sep 24 i i`- Re: Long filenames in DOS/Windows and Unix/Linux1Janis Papanagnou
1 Sep 24 i `- Arbitrary characters in filenames (was: Long filenames in DOS/Windows and Unix/Linux)1Helmut Waitzmann
31 Aug 24 +* Re: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to stdin)48Muttley
3 Sep 24 i`* Re: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to stdin)47John Ames
3 Sep 24 i +- Re: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to stdin)1Lew Pitcher
3 Sep 24 i +* Re: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to stdin)4Kenny McCormack
4 Sep 24 i i`* Re: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to3Muttley
4 Sep 24 i i `* User surveys (Was: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to)2Kenny McCormack
4 Sep 24 i i  `- Re: User surveys (Was: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to)1Muttley
3 Sep 24 i +* Re: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to stdin)40Kaz Kylheku
3 Sep 24 i i`* Re: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to stdin)39John Ames
3 Sep 24 i i +* Re: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to stdin)37Kaz Kylheku
3 Sep 24 i i i`* Re: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to stdin)36John Ames
3 Sep 24 i i i +- Re: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to stdin)1Lawrence D'Oliveiro
3 Sep 24 i i i `* Re: Long filenames in DOS/Windows and Unix/Linux34Keith Thompson
3 Sep 24 i i i  +* Re: Long filenames in DOS/Windows and Unix/Linux16Lawrence D'Oliveiro
4 Sep 24 i i i  i`* Re: Long filenames in DOS/Windows and Unix/Linux15Keith Thompson
4 Sep 24 i i i  i +* Re: Long filenames in DOS/Windows and Unix/Linux13Lawrence D'Oliveiro
4 Sep 24 i i i  i i+* Re: Long filenames in DOS/Windows and Unix/Linux4Keith Thompson
4 Sep 24 i i i  i ii`* Re: Long filenames in DOS/Windows and Unix/Linux3Lawrence D'Oliveiro
4 Sep 24 i i i  i ii `* Re: Long filenames in DOS/Windows and Unix/Linux2Keith Thompson
4 Sep 24 i i i  i ii  `- Re: Long filenames in DOS/Windows and Unix/Linux1Lawrence D'Oliveiro
4 Sep 24 i i i  i i`* Re: Long filenames in DOS/Windows and Unix/Linux8Ralf Fassel
4 Sep 24 i i i  i i `* Re: Long filenames in DOS/Windows and Unix/Linux7Keith Thompson
4 Sep 24 i i i  i i  `* Re: Long filenames in DOS/Windows and Unix/Linux6Nuno Silva
4 Sep 24 i i i  i i   `* Always use "--" (Was: Long filenames in DOS/Windows and Unix/Linux)5Kenny McCormack
4 Sep 24 i i i  i i    `* Re: Always use "--" (Was: Long filenames in DOS/Windows and Unix/Linux)4Lew Pitcher
4 Sep 24 i i i  i i     +- Re: Always use "--" (Was: Long filenames in DOS/Windows and Unix/Linux)1Lawrence D'Oliveiro
5 Sep 24 i i i  i i     `* Re: Always use "--" (Was: Long filenames in DOS/Windows and Unix/Linux)2Kaz Kylheku
5 Sep 24 i i i  i i      `- Re: Always use "--" (Was: Long filenames in DOS/Windows and Unix/Linux)1Lew Pitcher
4 Sep 24 i i i  i `- Re: Long filenames in DOS/Windows and Unix/Linux1Tim Rentsch
4 Sep 24 i i i  +* Re: Long filenames in DOS/Windows and Unix/Linux11Kaz Kylheku
4 Sep 24 i i i  i+* Re: Long filenames in DOS/Windows and Unix/Linux8Keith Thompson
4 Sep 24 i i i  ii`* Re: Long filenames in DOS/Windows and Unix/Linux7Lawrence D'Oliveiro
4 Sep 24 i i i  ii `* Re: Long filenames in DOS/Windows and Unix/Linux6Keith Thompson
4 Sep 24 i i i  ii  +* Re: Long filenames in DOS/Windows and Unix/Linux4Lawrence D'Oliveiro
4 Sep 24 i i i  ii  i`* Re: Long filenames in DOS/Windows and Unix/Linux3Keith Thompson
4 Sep 24 i i i  ii  i +- Re: Long filenames in DOS/Windows and Unix/Linux1Lawrence D'Oliveiro
4 Sep 24 i i i  ii  i `- Re: Long filenames in DOS/Windows and Unix/Linux1Nuno Silva
4 Sep 24 i i i  ii  `- Re: Long filenames in DOS/Windows and Unix/Linux1Kaz Kylheku
4 Sep 24 i i i  i`* Re: Long filenames in DOS/Windows and Unix/Linux2John Ames
4 Sep 24 i i i  i `- Re: Long filenames in DOS/Windows and Unix/Linux1Muttley
4 Sep 24 i i i  `* Re: Long filenames in DOS/Windows and Unix/Linux6Richard Kettlewell
5 Sep 24 i i i   `* Re: Long filenames in DOS/Windows and Unix/Linux5Ralf Fassel
5 Sep 24 i i i    +* Re: Long filenames in DOS/Windows and Unix/Linux3Richard Kettlewell
7 Sep 24 i i i    i`* Re: Long filenames in DOS/Windows and Unix/Linux2candycanearter07
7 Sep 24 i i i    i `- Word splitting oddities (Was: Long filenames in DOS/Windows and Unix/Linux)1Kenny McCormack
10 Sep 24 i i i    `- Re: Long filenames in DOS/Windows and Unix/Linux1Janis Papanagnou
10 Sep 24 i i `- Re: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to stdin)1Janis Papanagnou
4 Sep 24 i `- Re: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to1Muttley
1 Sep 24 `- Re: Long filenames in DOS/Windows and Unix/Linux (Was: Piping to stdin)1Marcel Mueller

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal