Interview Prep/Shell Scripting/Troubleshooting: syntax, parsing and interpreter errors

A script prints `/bin/sh: 1: [[: not found` and then continues as if the test were false.

BeginnerTroubleshootingTroubleshooting: syntax, parsing and interpreter errors
Answer

Likely causes → The script runs under dash (Ubuntu's /bin/sh), which has no [[. It was started with sh script.sh, has a #!/bin/sh shebang, or runs from a cron line or Dockerfile RUN (which uses /bin/sh -c).

Diagnose →

head -1 script.sh; ls -l /bin/sh
grep -n 'sh ' /etc/cron.d/* Dockerfile 2>/dev/null

Fix → Use #!/usr/bin/env bash and run it as ./script.sh or bash script.sh; in a Dockerfile use SHELL ["/bin/bash", "-o", "pipefail", "-c"]. Or rewrite the test in POSIX form with [ ] or case.

Prevent → Lint with ShellCheck; it warns when the shebang is sh and the code uses [[ (SC3010).

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: syntax, parsing and interpreter errors