`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).
More on Troubleshooting: syntax, parsing and interpreter errors
`./deploy.sh` fails with `bash: ./deploy.sh: /bin/bash^M: bad interpreter: No such file or directory` (or, on Bash 5.2, `cannot execute: required file not found`).Beginner`bash: ./backup.sh: Permission denied` right after cloning the repo.Beginner`deploy.sh: line 14: syntax error near unexpected token `fi'`Beginner`install.sh: line 87: syntax error: unexpected end of file`Beginner`warning: here-document at line 12 delimited by end-of-file (wanted `EOF')` and the rest of the script never runs.BeginnerA script prints `/bin/sh: 1: [[: not found` and then continues as if the test were false.Beginner