-
-
Save darkfeline/19a91aa9e59259bb61e4614a32091600 to your computer and use it in GitHub Desktop.
POSIX portable bash script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ -z "${BASH_VERSION}" ]; then | |
exec bash "$@" | |
fi | |
# Bash script here | |
echo "${BASH_VERSION}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pretty good, so long as no code exports
BASH_VERSION
into environment variables (which is a bad idea in most cases, but nearly inevitable given enough users, uses, and use-cases).Could protect against that case by adding another
if
like this:(To support ancient shells it would be best to replace
unset BASH_VERSION
withBASH_VERSION= export BASH_VERSION
but for anything from the last decade or two it's probably overkill.)