Re: Which shell and how to get started handling arguments

Liste des GroupesRevenir à cu shell 
Sujet : Re: Which shell and how to get started handling arguments
De : lew.pitcher (at) *nospam* digitalfreehold.ca (Lew Pitcher)
Groupes : comp.unix.shell
Date : 15. Apr 2024, 17:06:31
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <uvjfpn$b4oi$1@dont-email.me>
References : 1
User-Agent : Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2)
On Mon, 15 Apr 2024 13:22:14 +0100, James Harris wrote:

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?

As others have said, write your script to the POSIX shell language
standards. (see
  https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html)

Most shells support this restricted dialect.


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

The "simple but universal way" is to sequentially parse your argument list.
But, this leads to complications that may not sit with your script design,
in that you (the programmer) have to decide on whether or not you want
to impose a specific order to the argument list, and, following that
decision, how you want to handle "unflagged" arguments.

Then, there is getopts (which is /not/ a universally-supported extension
to the shell language), which will handle the argument list for you, but
with caveats and argument list order decisions that you might not agree
with.

For the most part, the "simple but universal" rule is "KISS" (Keep It Simple
& Sequential), with flags first, and non-flag arguments in a fixed order,
after the flags.


HTH
--
Lew Pitcher
"In Skills We Trust"

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