Frequently Asked Question
Why does the shell sometimes complain about /bin/sh vs /bin/bash?
The first line of a script (the shebang like #!/bin/bash or #!/bin/sh)
tells the kernel which interpreter to run the script with. If you write
#!/bin/sh and then use bash-only features (arrays, [[ ... ]], <<<,
${var,,}, function name()), the script will work when bash is invoked as
sh (because bash falls back to mostly-POSIX behaviour) but break completely on
systems where /bin/sh is dash, notably Debian and Ubuntu.
The fix is to be honest about which interpreter you need. If the script is
portable POSIX shell, use #!/bin/sh and stick to POSIX features. If it uses bash
extensions, use #!/bin/bash (or #!/usr/bin/env bash for slightly better
portability between BSDs and Linux). ShellCheck (shellcheck script.sh) is the
standard linter: it'll flag bashisms in sh scripts and other common mistakes
before they bite you.