Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Extreme fear can neither fight nor fly. -- William Shakespeare, "The Rape of Lucrece"


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

SubjectAuthor
o Re: Which shell and how to get started handling argumentsHelmut Waitzmann

1
Subject: Re: Which shell and how to get started handling arguments
From: Helmut Waitzmann
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Mon, 15 Apr 2024 21:49 UTC
References: 1
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: Mon, 15 Apr 2024 23:49:33 +0200
Organization: A noiseless patient Spider
Lines: 49
Sender: Helmut Waitzmann <12f7e638@mail.de>
Message-ID: <83wmoy9tzm.fsf@helmutwaitzmann.news.arcor.de>
References: <uvj65n$9aep$1@dont-email.me>
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: Mon, 15 Apr 2024 23:57:50 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2bcbbffe7cad399a53874fa117e3a011";
logging-data="553575"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bt1dYkuu4nYtNh94q+9KamHEy2kfmeEs="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Cancel-Lock: sha1:XUcA9Oi6r8jvYBI9f/xUy6NU/vE=
sha1:heGwfpYr4KvFztPoDyxSUbL1dNM=
Mail-Copies-To: nobody
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
View all headers

James Harris <james.harris.1@gmail.com>:

> I read up on getopts but from tests it seems to require that
> switches precede arguments
>

Yes, that's true.

> rather than allowing them to be specified after, so that doesn't
> seem very good, either.
>

The problem with specifying options after non‐option arguments is
that non‐option arguments may take any form:  They even may start
with an "-", that is, look like options even when they aren't
meant to be used as options.

So, if you have some command "some_command" with one non‐option
argument "a" followed by an option "-b"

$ some_command -a -b

and parse the arguments from left to right then there is no way
for "some_command" to investigate that "-a" is to be taken as a
non‐option argument while "-b" is to be taken as an option.

Whereas, when "some_command" expects options before any
non‐option argument and recognizes the end‐of‐options marker
("--") then there is no ambiguity:

$ some_command -b -- -a

"-b" is an option, while "-a" (because the series of options is
terminated by the end‐of‐options marker) is the (first)
non‐option argument "-a".

That's the way how the POSIX‐shell builtin "getopts" works.

1

rocksolid light 0.9.8
clearnet tor