A bash script is run with sh
Commonsh script.sh, a #!/bin/sh shebang, a Dockerfile RUN line, a Makefile recipe or a CI step whose shell is sh.
Confirm
head -1 script.sh readlink -f /bin/sh
#!/bin/sh or a sh call, with /bin/sh pointing to dash
Fix
- Use #!/usr/bin/env bash and run the script directly or with bash script.sh.
- In a Dockerfile, add SHELL ["/bin/bash", "-o", "pipefail", "-c"] before RUN lines that need bash.
- In a Makefile, set SHELL := /bin/bash. GNU Make 4.3 on Ubuntu 24.04 ran a recipe with [[ ]] under /bin/sh, printed [[: not found and carried on; with SHELL := /bin/bash the same recipe worked.
#!/usr/bin/env bash set -euo pipefail
Reproduced on Ubuntu 24.04: the same file ran under bash.