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

`bash: [: missing `]'`

BeginnerTroubleshootingTroubleshooting: syntax, parsing and interpreter errors
Answer

Likely causes → [ is a command and ] must be its last, separate argument. Missing space ([ -f "$f"]), using && inside [ ] ([ -f a && -f b ]), or an unquoted variable expanding to nothing in the wrong place.

Diagnose → bash -x script.sh shows the exact [ command after expansion.

Fix → [ -f "$f" ], [ -f a ] && [ -f b ], or use Bash's [[ -f a && -f b ]].

Prevent → Prefer [[ ]] in Bash scripts; ShellCheck catches missing spaces (SC1020) and && inside [ ] (SC2107).

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: syntax, parsing and interpreter errors