Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <uvj65n$9aep$1@dont-email.me>
Deutsch   English   Français   Italiano  
<uvj65n$9aep$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: James Harris <james.harris.1@gmail.com>
Newsgroups: comp.unix.shell
Subject: Which shell and how to get started handling arguments
Date: Mon, 15 Apr 2024 13:22:14 +0100
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <uvj65n$9aep$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 15 Apr 2024 14:22:16 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="409d45fe40fc26abb5e777df2efce117";
	logging-data="305625"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18yqgNf2YfcfWyBkKoY5WfoAUDTGFLJYIY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:mnrl26r31LNO3kvdryOVkkHFgZ8=
Content-Language: en-GB
Bytes: 2507

For someone who is relatively new to Unix shell scripting (me) some 
advice would be more than welcome on where to begin.

I have two main queries:


Q1) How can one write a script which is maximally compatible with 
different systems?

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.)

Or is Bash now so universal that there's no point any longer in writing 
for anything else?


Q2) How does one go about handling arguments in preferably a simple but 
universal way?

My first idea was to iterate over arguments with such as

while [ $# -gt 0 ]
do
   ...
   shift
done;

and from that to (a) note any switches and (b) build up an array of 
positional parameters. However, I gather the Bourne shell has no arrays 
(other than the parameters themselves) so that won't work.

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.


Online tutorials show different ways to handle this and few talk about 
which shell to use for this case so I thought I would ask you guys for 
suggestions.

My requirement just now is, in fact, so simple that I don't need a 
universal way to handle things but ISTM best to start with an approach 
that will scale over time, if there is one.

So any guidance on how to get started would be appreciated!


-- 
James Harris