Which shell and how to get started handling arguments

Liste des GroupesRevenir à cu shell 
Sujet : Which shell and how to get started handling arguments
De : james.harris.1 (at) *nospam* gmail.com (James Harris)
Groupes : comp.unix.shell
Date : 15. Apr 2024, 13:22:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <uvj65n$9aep$1@dont-email.me>
User-Agent : Mozilla Thunderbird
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

Date Sujet#  Auteur
15 Apr 24 * Which shell and how to get started handling arguments26James Harris
15 Apr 24 +* Re: Which shell and how to get started handling arguments2Janis Papanagnou
15 Apr 24 i`- Re: Which shell and how to get started handling arguments1Janis Papanagnou
15 Apr 24 +* Re: Which shell and how to get started handling arguments4Christian Weisgerber
15 Apr 24 i`* Re: Which shell and how to get started handling arguments3Helmut Waitzmann
16 Apr 24 i `* Re: Which shell and how to get started handling arguments2Kaz Kylheku
16 Apr 24 i  `- Re: Which shell and how to get started handling arguments1Helmut Waitzmann
15 Apr 24 +- Re: Which shell and how to get started handling arguments1Ben Bacarisse
15 Apr 24 +* Re: Which shell and how to get started handling arguments16Lew Pitcher
15 Apr 24 i+* Re: Which shell and how to get started handling arguments4Christian Weisgerber
15 Apr 24 ii+* Re: Which shell and how to get started handling arguments2Kenny McCormack
15 Apr 24 iii`- Re: Which shell and how to get started handling arguments1Kaz Kylheku
15 Apr 24 ii`- Re: Which shell and how to get started handling arguments1Lew Pitcher
15 Apr 24 i`* Re: Which shell and how to get started handling arguments11Keith Thompson
16 Apr 24 i +- Re: Which shell and how to get started handling arguments1Janis Papanagnou
16 Apr 24 i `* Re: Which shell and how to get started handling arguments9Christian Weisgerber
16 Apr 24 i  +* Re: Which shell and how to get started handling arguments3Keith Thompson
16 Apr 24 i  i`* Re: Which shell and how to get started handling arguments2Kenny McCormack
16 Apr 24 i  i `- Re: Which shell and how to get started handling arguments1Christian Weisgerber
16 Apr 24 i  +* Re: Which shell and how to get started handling arguments2Kaz Kylheku
17 Apr 24 i  i`- Re: Which shell and how to get started handling arguments1Keith Thompson
17 Apr 24 i  `* Re: Which shell and how to get started handling arguments3Lawrence D'Oliveiro
17 Apr 24 i   +- Re: Which shell and how to get started handling arguments1Kenny McCormack
17 Apr 24 i   `- Re: Which shell and how to get started handling arguments1Christian Weisgerber
15 Apr 24 +- Re: Which shell and how to get started handling arguments1Helmut Waitzmann
16 Apr 24 `- Re: Which shell and how to get started handling arguments1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal