Sujet : Re: Which shell and how to get started handling arguments
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.unix.shellDate : 16. Apr 2024, 02:14:38
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240415173857.41@kylheku.com>
References : 1 2 3
User-Agent : slrn/pre1.0.4-9 (Linux)
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/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca