Interview Prep/Shell Scripting/Troubleshooting: tools, portability, permissions and environment

A Bash script copied into an `alpine` image fails with `env: can't execute 'bash': No such file or directory`.

BeginnerTroubleshootingTroubleshooting: tools, portability, permissions and environment
Answer

Likely causes → Alpine ships BusyBox ash as /bin/sh and does not include Bash. The shebang #!/usr/bin/env bash finds nothing.

Diagnose →

docker run --rm alpine:3.20 sh -c 'command -v bash || echo "no bash"'
head -1 entrypoint.sh

Fix → Install Bash in the image, or make the script POSIX sh and change the shebang:

FROM alpine:3.20
RUN apk add --no-cache bash
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

If you convert to #!/bin/sh, check it with shellcheck -s sh entrypoint.sh to catch Bashisms.

Prevent → Decide per image which shell you target, and lint with the matching ShellCheck dialect in CI.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: tools, portability, permissions and environment