Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #399: We are a 100% Microsoft Shop.


comp / comp.unix.shell / Re: Which shell and how to get started handling arguments

SubjectAuthor
* Re: Which shell and how to get started handling argumentsKaz Kylheku
`- Re: Which shell and how to get started handling argumentsHelmut Waitzmann

1
Subject: Re: Which shell and how to get started handling arguments
From: Kaz Kylheku
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Tue, 16 Apr 2024 01:14 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Which shell and how to get started handling arguments
Date: Tue, 16 Apr 2024 01:14:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <20240415173857.41@kylheku.com>
References: <uvj65n$9aep$1@dont-email.me>
<slrnv1qb9c.1cbm.naddy@lorvorc.mips.inka.de>
<831q76bao7.fsf@helmutwaitzmann.news.arcor.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 16 Apr 2024 03:14:38 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="1682384890190e36c4f114beff04a46e";
logging-data="625584"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/X1dOCijFTHsIFqh/ZlLcqtyTdC0Frcrs="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:AKhvjA9YqH9vX/VasEBzWdrlV1o=
View all headers

On 2024-04-15, Helmut Waitzmann <nn.throttle@xoxy.net> wrote:
> Compare (using GNU ls) with Christians well‐behaving "ls":
>
>
> touch -- foo -l
>
> $ ls foo -l
> -rw------- 1 helmut helmut 0 Apr 15 15:28 foo

touch deviates in the first place; omit the -- and you get

$ touch foo -l
touch: invalid option -- 'l'

That's crazy. foo is a non-option argument, so the options
have ended at that point.

I see where it is documented in "2 Common options" (Coreutils manual):

Normally options and operands can appear in any order, and programs act
as if all the options appear before any operands. For example, ‘sort -r
passwd -t :’ acts like ‘sort -r -t : passwd’, since ‘:’ is an
option-argument of -t. However, if the POSIXLY_CORRECT environment
variable is set, options must appear before operands, unless otherwise
specified for a particular command.

It is disingenous to call it "POSIXly correct", because in fact the
POSIX rules are how everyone understands it and how other implementors
of utilities implement it. (Does anyone else do this crazy thing?)

If all the vendors feature a given extension, so that it is portable,
but POSIX refuses to adopt it, then, sure: the mode which takes the
extension away can be flippantly called "POSIXly correct".

Also the claim "options must appear before operands [in POSIX]" is
misleading, because "must" is usually interpreted as an imposed
requirement, which can be violated and diagnosed. But in fact it is
*logically* impossible for options to appear elsewhere because arguments
that look like options placed in the non-option part of the command line
are operands. It's the logical "must", not the reuqirements "must".

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

Subject: Re: Which shell and how to get started handling arguments
From: Helmut Waitzmann
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Tue, 16 Apr 2024 20:23 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nn.throttle@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: Which shell and how to get started handling arguments
Date: Tue, 16 Apr 2024 22:23:46 +0200
Organization: A noiseless patient Spider
Lines: 95
Sender: Helmut Waitzmann <12f7e638@mail.de>
Message-ID: <83r0f59hv1.fsf@helmutwaitzmann.news.arcor.de>
References: <uvj65n$9aep$1@dont-email.me>
<slrnv1qb9c.1cbm.naddy@lorvorc.mips.inka.de>
<831q76bao7.fsf@helmutwaitzmann.news.arcor.de>
<20240415173857.41@kylheku.com>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Injection-Date: Tue, 16 Apr 2024 22:28:39 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="44cf11a42b0baf5bda51faf8d77e2ac9";
logging-data="1202959"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/EJqKqr1Z/h7isKsEHZqGiSWmozmBislM="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Cancel-Lock: sha1:LO1WavU5XHEubZAEjcYTmCXQGp4=
sha1:qQaIDhRW85IVNgUDm8z1l7+Xu2M=
Mail-Copies-To: nobody
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
View all headers

Kaz Kylheku <643-408-1753@kylheku.com>:
> On 2024-04-15, Helmut Waitzmann <nn.throttle@xoxy.net> wrote:
>> Compare (using GNU ls) with Christians well‐behaving "ls":
>>
>>
>> touch -- foo -l
>>
>> $ ls foo -l
>> -rw------- 1 helmut helmut 0 Apr 15 15:28 foo
>
> touch deviates in the first place; omit the -- and you get
>
>
> $ touch foo -l
> touch: invalid option -- 'l'
>
> That's crazy. foo is a non-option argument, so the options
> have ended at that point.
>

Yes, that's the same problem like with GNU "ls".  (I decided to
silently avoid it by making use of the end‐of‐option marker
without commenting it.)

> I see where it is documented in "2 Common options" (Coreutils
> manual):
>
>
> Normally options and operands can appear in any order, and
> programs act as if all the options appear before any operands.
> For example, ‘sort -r passwd -t :’ acts like ‘sort -r -t :
> passwd’, since ‘:’ is an option-argument of -t. However, if
> the POSIXLY_CORRECT environment variable is set, options must
> appear before operands, unless otherwise specified for a
> particular command.
>

If I understand the last sentence correctly, setting the
POSIXLY_CORRECT environment variable forces the GNU utilities to
stop option processing before the first non‐option argument
(i. e. an argument beginning not with a "-") as if that argument
had been preceded by the end‐of‐option argument "--".

> It is disingenous to call it "POSIXly correct", because in fact
> the POSIX rules are how everyone understands it and how other
> implementors of utilities implement it. (Does anyone else do
> this crazy thing?)
>
>
> If all the vendors feature a given extension, so that it is
> portable, but POSIX refuses to adopt it, then, sure: the mode
> which takes the extension away can be flippantly called "POSIXly
> correct".
>

Maybe my knowledge of the English language is not good enough to
understand you correctly.  Under the premise, that the
POSIXLY_CORRECT environment variable has been set, do you see the
GNU utilities behaving in any different way from what is the
behavior specified by POSIX?

> Also the claim "options must appear before operands [in POSIX]"
> is misleading, because "must" is usually interpreted as an
> imposed requirement, which can be violated and diagnosed. But in
> fact it is *logically* impossible for options to appear
> elsewhere because arguments that look like options placed in the
> non-option part of the command line are operands. It's the
> logical "must", not the reuqirements "must".
>

The GNU manual does not say "in POSIX" but says "if the
POSIXLY_CORRECT environment variable is set", but otherwise I
agree with you.  This is, why I recommend to not make use of the
GNU behavior of looking for options right of the first non‐option
operand when neither the end‐of‐option marker is used nor the
POSIXLY_CORRECT environment variable has been set, but rather
always put any options (if present) first, then – regardless of
whether any options are actually present – in any case supply the
end‐of‐option marker ("--") and finally any non‐option operands. 
This way both, POSIX utilities and GNU utilities, will behave the
same, even, if the POSIXLY_CORRECT environment variable happens
not to be set.

1

rocksolid light 0.9.8
clearnet tor