Sujet : Re: Which shell and how to get started handling arguments
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.unix.shellDate : 15. Apr 2024, 18:38:34
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <uvjomq$3qo86$1@news.xmission.com>
References : 1 2 3
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
slrnv1qib9.1f89.naddy@lorvorc.mips.inka.de>,
Christian Weisgerber <
naddy@mips.inka.de> wrote:
On 2024-04-15, Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
>
As others have said, write your script to the POSIX shell language
standards.
>
Then, there is getopts (which is /not/ a universally-supported extension
to the shell language),
>
It is part of POSIX sh.
It would be useful to know exactly *why* OP wants to stay "as portable as
possible". Yes, I know it is against the creed here to question such
things, but it needs to be done, nevertheless.
I say this as someone who does occasionally program in dash (Debian's
version of the "POSIX shell" paradigm), just to see and to remind myself
about how limited it is. But I would urge OP to think long and hard about
whether or not it matters. I find that when I do program in dash, I rather
quickly run into the limitations and end up regretting the choice.
For example, many things exist in both bash (my preferred shell programming
language, just in case such had not been made clear by now) and in "POSIX"
shell, but have limited functionality in the POSIX version. So, if you are
used to the full functionality you get in the bash version, you can get
bitten if you assume that the "POSIX" version has the same functionality.
I mention this specifically because you mentioned "getopts" - which does
indeed exist in both bash and dash, but I'd be willing to bet, has limited
functionality in the dash version. I never use "getopts", so I don't know
this for a fact; I am just speculating. I know it *is* true for some other
shell commands/functions.
In general, I just don't find it worth the bother to limit myself to a
crippled shell.
But, mind you, it is possible, though unlikely, that OP actually has a
good/valid reason for doing so. Mostly, I think it is just virtue
signalling.
-- When I was growing up we called them "retards", but that's not PC anymore.Now, we just call them "Trump Voters".The question is, of course, how much longer it will be until that term is also un-PC.