~alpine/users

9 8

Resources for learning shell scripting

Paul Zillmann <p.zillmann@h6g.de>
Details
Message ID
<d1738ee7-115d-4851-8514-8b5eb3adb002@h6g.de>
DKIM signature
missing
Download raw message
Hello there,

recently I have to write a bit of shell scripts and I find myself with 
the problem of finding solutions online that are compatible with GNU 
bash, but not with busyboxes POSIX shell.
So I would spend a bit of time to adapt those scripts to be able to run 
with /bin/ash.

Could you recommend any good resources to learn how to script for POSIX 
in the first place?
Are there any good websites, books or even man pages available?

I'm not a very good bash scripter myself, usually I work with compiled 
languages like C and Golang.

Thanks,
- Paul
Details
Message ID
<ZzyrYnOLizBAvg30@motherbrain>
In-Reply-To
<d1738ee7-115d-4851-8514-8b5eb3adb002@h6g.de> (view parent)
DKIM signature
missing
Download raw message
On Tue, Nov 19, 2024 at 03:57:42PM +0100, Paul Zillmann wrote:
>Could you recommend any good resources to learn how to script for 
>POSIX in the first place?
>Are there any good websites, books or even man pages available?

Hello.

Reading different Bourne shell implementations man pages can help a 
lot. I recommend NetBSD and OpenBSD sh(1) man page.

There may be some Alpine specific software written in Bourne shell 
(openrc? which is actually not Alpine specific...), but I not too 
familiar with Alpine to recommend any.

Reading good implementations of programs writting in Bourne shell can 
help as well. On the top of my head, I remember acme.sh and NetBSD 
postinstall programs can be good refereces.

There may be other good resources on the web.  Some examples:

http://www.shelldorado.com/

David Wheeler's articles about shell security, like this one: 
https://dwheeler.com/essays/filenames-in-shell.html
Paul Zillmann <p.zillmann@h6g.de>
Details
Message ID
<54e52224-054d-4f13-a829-732e7c4ca964@h6g.de>
In-Reply-To
<ZzyrYnOLizBAvg30@motherbrain> (view parent)
DKIM signature
missing
Download raw message
Am 19.11.24 um 16:14 schrieb Silas:
> Reading different Bourne shell implementations man pages can help a 
> lot. I recommend NetBSD and OpenBSD sh(1) man page.
>

I almost forgot that with anything POSIX I can check out Unix' resources.
Might also be a good keyword - thank you.

- Paul
Details
Message ID
<23ab2b65-217d-4e5e-b7c5-b6cdf61bdb30@regrow.earth>
In-Reply-To
<d1738ee7-115d-4851-8514-8b5eb3adb002@h6g.de> (view parent)
DKIM signature
missing
Download raw message
Hi!

I can recommend https://shellhaters.org as a quick way to find all the 
POSIX documentation, both for shell syntax and all the 
commands/utilities. I use it all the time :)

Best,
Edin
Edward Miles Stapleton <cerement@gmail.com>
Details
Message ID
<CANrdkm4RzynGntJeu-aO4f3-Y9reHa8w7JWjkxCJR3DAnnNKdQ@mail.gmail.com>
In-Reply-To
<d1738ee7-115d-4851-8514-8b5eb3adb002@h6g.de> (view parent)
DKIM signature
missing
Download raw message
On Tue, Nov 19, 2024 at 6:58 AM Paul Zillmann <p.zillmann@h6g.de> wrote:
> Are there any good websites, books or even man pages available?

I've seen decent reviews for *Classic Shell Scripting*:
Arnold Robbins & Nelson H.F. Beebe, *Classic Shell Scripting* (O'Reilly, 2005)
Edward Miles Stapleton <cerement@gmail.com>
Details
Message ID
<CANrdkm7K=RpmPA6dKoUD0ggOFKQML58AsQoVEbE-XSz3XAoFsg@mail.gmail.com>
In-Reply-To
<d1738ee7-115d-4851-8514-8b5eb3adb002@h6g.de> (view parent)
DKIM signature
missing
Download raw message
On Tue, Nov 19, 2024 at 6:58 AM Paul Zillmann <p.zillmann@h6g.de> wrote:
> Are there any good websites, books or even man pages available?

there's also the `shellcheck` tool (in the community repository):
https://github.com/koalaman/shellcheck
Steffen Nurpmeso <steffen@sdaoden.eu>
Details
Message ID
<20241119190340.nHqfWGEL@steffen%sdaoden.eu>
In-Reply-To
<d1738ee7-115d-4851-8514-8b5eb3adb002@h6g.de> (view parent)
DKIM signature
missing
Download raw message
Paul Zillmann wrote in
 <d1738ee7-115d-4851-8514-8b5eb3adb002@h6g.de>:
 |recently I have to write a bit of shell scripts and I find myself with 
 |the problem of finding solutions online that are compatible with GNU 
 |bash, but not with busyboxes POSIX shell.
 |So I would spend a bit of time to adapt those scripts to be able to run 
 |with /bin/ash.
 |
 |Could you recommend any good resources to learn how to script for POSIX 
 |in the first place?
 |Are there any good websites, books or even man pages available?
 |
 |I'm not a very good bash scripter myself, usually I work with compiled 
 |languages like C and Golang.

Sven Mascheck is "an instance" regarding history of shell and
compatibility, used even by shell standard developers like Chet
Ramey (bash), dear Jörg Schilling (bosh), and other shell experts
like Stephane Chazelas:

  https://www.in-ulm.de/~mascheck/

Other than that it is a good idea to write scripts in shells which
are dedicated to POSIX compatibility, like dash.

(I have no idea of those "shell-check" tools which exist, many
swear by them.)

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)
|
|And in Fall, feel "The Dropbear Bard"s ball(s).
|
|The banded bear
|without a care,
|Banged on himself fore'er and e'er
|
|Farewell, dear collar bear
Richard Brooksby <rptb1+alpine@pobox.com>
Details
Message ID
<bb7715ab-1193-45d7-ae78-a1f343ead211@pobox.com>
In-Reply-To
<d1738ee7-115d-4851-8514-8b5eb3adb002@h6g.de> (view parent)
DKIM signature
missing
Download raw message
On 2024-11-19 14:57, Paul Zillmann wrote:
> Could you recommend any good resources to learn how to script for POSIX
> in the first place?

I highly recommend a habit of running your scripts through shellcheck 
<https://www.shellcheck.net/>, which is probably available from the 
package system of your distro (e.g. "apt-get install shellcheck").

I've been writing shell scripts for decades and it still catches my 
mistakes.  It gives good and specific advice.  And investigating *why* 
it gives advice is great for learning.

> I'm not a very good bash scripter myself, usually I work with compiled
> languages like C and Golang.
Shells have grown rather organically and have fewer unifying principles 
than those languages.  Be prepared for weirdness.
Details
Message ID
<OC74UOO--B-9@keemail.me>
In-Reply-To
<d1738ee7-115d-4851-8514-8b5eb3adb002@h6g.de> (view parent)
DKIM signature
missing
Download raw message
You should either try guide.bash.academy or https://tldp.org/LDP/abs/html/. Both are very good and practical.

Cheers.

19 Nov 2024, 20:28 by p.zillmann@h6g.de:

> Hello there,
>
> recently I have to write a bit of shell scripts and I find myself with the problem of finding solutions online that are compatible with GNU bash, but not with busyboxes POSIX shell.
> So I would spend a bit of time to adapt those scripts to be able to run with /bin/ash.
>
> Could you recommend any good resources to learn how to script for POSIX in the first place?
> Are there any good websites, books or even man pages available?
>
> I'm not a very good bash scripter myself, usually I work with compiled languages like C and Golang.
>
> Thanks,
> - Paul
>
Details
Message ID
<a57e61eefbf1922b1cae08a659b6873bc8d93fc3.camel@riseup.net>
In-Reply-To
<OC74UOO--B-9@keemail.me> (view parent)
DKIM signature
missing
Download raw message
On Wed, 2024-11-20 at 06:40 +0100, spoon@keemail.me wrote:
> You should either try guide.bash.academy
> or https://tldp.org/LDP/abs/html/. Both are very good and practical.

The “Advanced Bash Scripting Guide” is far from what the OP is asking
for! Bash provides arrays and so on.

Bashisms are frowned upon for portability.
Reply to thread Export thread (mbox)