by eltoozero · 8y ago · 0 comments
I have been enjoying "Beginning Portable Shell Scripting"[0] by Peter Seebach for this very reason.
I highly recommend it (and the POSIX docs) to anyone who is is interested in portable shell programming.
---Alex
$ 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. ;)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).