:: [DNG] POSIX shell scripting (was: D…
Inizio della pagina
Delete this message
Reply to this message
Autore: spiralofhope
Data:  
To: dng
Vecchi argomenti: Re: [DNG] Danger: Debian POSIX hostility
Oggetto: [DNG] POSIX shell scripting (was: Danger: Debian POSIX hostility)
In response to nobody in particular..

I've always started shells with

#!/usr/bin/env sh

I now go *way* out of my way to not just remove bashisms but replace
anything I can with POSIX compatible code. Call it puritanism as
practice.

I lint with Shellcheck:

http://www.shellcheck.net/

The pure sh bible has been a big help:

https://github.com/dylanaraps/pure-sh-bible

Here are some examples of replacing "standard" software:

https://github.com/spiralofhope/shell-random/blob/master/live/sh/scripts/examples/replace-head.sh

https://github.com/spiralofhope/shell-random/blob/master/live/sh/scripts/examples/replace-dirname.sh


--


If anyone wants to see the lengths I've gone to:

https://github.com/spiralofhope/shell-random/tree/master/live/sh/scripts

https://github.com/spiralofhope/shell-random/tree/master/live/sh/scripts/examples

Of course it's slower to use scripts that summon other scripts, as my
repository does, but it's easy enough to copy-paste functions into the
primary script. Only startup scripts are time-sensitive for me, and
everything else gains great clarity by separating functions out into
separate scripts.


In my preemptive defence, my style is clean and clear to me and allows
for reading using columns. With that, a simple idea becomes a simple
script:

https://github.com/spiralofhope/shell-random/blob/master/live/sh/scripts/is-string-a-date?.sh