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

    From Kenny McCormack@21:1/5 to nunojsilva@invalid.invalid on Wed Sep 4 13:04:07 2024
    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.

    --
    "Women should not be enlightened or educated in any way. They should be segregated because they are the cause of unholy erections in holy men.

    -- Saint Augustine (354-430) --

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to Kenny McCormack on Wed Sep 4 13:17:48 2024
    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

    HTH
    --
    Lew Pitcher
    "In Skills We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Lew Pitcher on Wed Sep 4 21:35:07 2024
    On Wed, 4 Sep 2024 13:17:48 -0000 (UTC), Lew Pitcher wrote:

    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.

    All the good ones do. This is why getopt(3) with POSIXLY_CORRECT stops
    looking for options as soon as a nonoption argument is encountered.

    Remember also that arguments need not necessarily be file names, so
    prefixing them all with “./” willy-nilly may not produce the right result anyway.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Lew Pitcher on Thu Sep 5 02:29:49 2024
    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.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to Kaz Kylheku on Thu Sep 5 14:48:31 2024
    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"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)