2 ms·
Something along these lines would allow using bash without making your script completely broken: #!/bin/sh if [ -z "$BASH_VERSION" ]; then if w
by skywhopper 13y ago
Something along these lines would allow using bash without making your script completely broken:
#!/bin/sh
if [ -z "$BASH_VERSION" ]; then
if which bash >/dev/null 2>/dev/null; then
exec bash "$0"
else
echo "ERROR: bash was not in your PATH" >&2
exit 1
fi
fi
# now start using bash-only shortcuts safely
if [[ "hello" == "hello" ]]; then
echo Bash has been achieved.
fi
I'm not promising that's completely foolproof (it clearly isn't), but it works with the default Ubuntu 13.10 config of having /bin/sh linked to /bin/dash. And you could easily expand on the idea to look in specific locations for the bash binary even if it's not in the path, check those binary's versions, etc.
- Hello71 13y agoand it doesn't work with bash-specific shell syntax, which will error upon script parsing in POSIX shells.