3 ms·
Sometimes - perhaps often - you are in situations where you have no control over the shell, in these cases writing "portable" shell scripts is helpful. I have
by eltoozero 9y ago
Sometimes - perhaps often - you are in situations where you have no control over the shell, in these cases writing "portable" shell scripts is helpful.
I have been enjoying "Beginning Portable Shell Scripting"[0] by Peter Seebach for this very reason.
[0]https://www.apress.com/us/book/9781430210436 https://www.apress.com/us/book/9781430210436
- majewsky 9y ago$ cat run-bash-script.sh #!/bin/sh which bash &>/dev/null && exec bash "$@" source /etc/os-release case "$ID" in debian) apt install bash || exit 1 ;; redhat|suse) yum install bash || exit 1 ;; arch) pacman -S bash || exit 1 ;; alpine) apk add bash || exit 1 ;; esac exec bash "$@" I don't know how to detect and handle the BSDs etc., but you get the idea. ;)
- chubot 9y agoAlso known as, "it's easier to port a shell than a shell script" :)
- deadbunny 9y agoNow go try that on AIX boxes, in banks, where you don't get root/sudo.
- oblio 9y agoYou also don't get internet access, in case a bright bulb tries to go "curl ...". Though in many of these cases I'd just advise leaving the premises unless the salary is stellar (or there are other considerations such as family, etc).
- deadbunny 9y agoOn the DevOps side of things (Contracting in London) the day rate at banks is about 1.5x everywhere else which can be nice. Just as long as you're happy never getting anything done ever.
- Alexqw85 9y agoI would like to second this recommendation. I have found "Beginning Portable Shell Scripting" to be invaluable --- and far more comprehensive than I expected given the "Beginning" in the title. I highly recommend it (and the POSIX docs) to anyone who is is interested in portable shell programming. ---Alex