Sujet : Re: Which shell and how to get started handling arguments
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.unix.shellDate : 16. Apr 2024, 00:20:34
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <uvk97i$h2pg$4@dont-email.me>
References : 1
User-Agent : Pan/0.155 (Kherson; fc5a80b8)
On Mon, 15 Apr 2024 13:22:14 +0100, James Harris wrote:
I am thinking to write in /the language of/ the Bourne shell, if
feasible, so that it could be run by either the Bourne shell or Bash,
etc? (Ideally, the shebang line would be #!/bin/sh.)
There is such a thing as a standardized “POSIX shell”. On Debian, for
example, /bin/sh will launch Dash, which is a minimal POSIX-compliant
shell.
It’s certainly a safe, boring choice. ;)
Or is Bash now so universal that there's no point any longer in writing
for anything else?
This is where we get into “Unix®” the trade mark, versus “Unix” as an
informal description of a collection of traditional OS behaviour.
I say this because the only currently “Unix®” trade mark licensee still
seeing any significant use is Apple’s macOS, and that does not offer
Bash--at least, not any reasonably recent version. This is for ideological
reasons or something.
So if you are targeting “Unix” in the latter sense, then Bash is quite
widespread, yes.
I read up on getopts but from tests it seems to require that switches
precede arguments rather than allowing them to be specified after, so
that doesn't seem very good, either.
One reason for that convention is that it is possible for file/directory
names to begin with “-”. To minimize the confusion this causes, there is a
an additional common convention among command-line tools that a plain “--”
option means “don’t look for any more options after this”. That is to say,
treat the remaining items as file names (or whatever else the program does
with them), even if they begin with “-”.