`[[ $line =~ ^ERROR (.*)$ ]]` fails with `syntax error in conditional expression`.
AdvancedTroubleshootingTroubleshooting: syntax, parsing and interpreter errors
Answer
Likely causes → Unquoted spaces inside the regex split it into separate words that [[ ]] cannot parse. Quoting the whole regex fixes the syntax but makes it a literal string match.
Diagnose → Test the regex alone in a variable and print BASH_REMATCH.
Fix → Store the regex in a variable and expand it unquoted:
re='^ERROR (.*)$'
if [[ $line =~ $re ]]; then msg=${BASH_REMATCH[1]}; fi
Or escape the space: ^ERROR\ (.*)$.
Prevent → Always put non-trivial regexes in a variable; it also makes them readable and reusable.
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.Beginner`bash: [: missing `]'`Beginner