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