Interview Prep/Shell Scripting/ShellCheck, debugging, testing, portability and security

When must a script be POSIX `sh` rather than Bash?

BeginnerConceptShellCheck, debugging, testing, portability and security
Answer

When Bash may not exist: Alpine and BusyBox-based images (only ash), distroless images with a shell, initramfs, embedded devices, Docker HEALTHCHECK or entrypoints in minimal images, and /bin/sh -c contexts you do not control (Makefiles by default, some CI runners, system() calls). Everywhere else, we use Bash explicitly and get arrays and [[ ]].

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on ShellCheck, debugging, testing, portability and security