`bash: [: =: unary operator expected`
BeginnerTroubleshootingTroubleshooting: quoting, expansion and tool-input bugs
Answer
Likely causes → The left-hand variable is empty and unquoted, so [ $env = prod ] becomes [ = prod ]. Usually a missing argument, a failed command substitution, or a typo in the variable name.
Diagnose → bash -x shows + '[' = prod ']'. Check where the variable is set.
Fix → [ "$env" = prod ] or [[ $env == prod ]], and validate required values early with : "${env:?env is required}".
Prevent → set -u catches unset (not empty) variables; quoting handles empty ones.
More on Troubleshooting: quoting, expansion and tool-input bugs
`bash: [: too many arguments`BeginnerA disk check fails with `[: 93%: integer expression expected`Beginner`rm $file` fails with `rm: cannot remove 'monthly': No such file or directory` and `rm: cannot remove 'report.csv'`.BeginnerA cleanup script logs `cp: cannot stat '/var/log/app/*.log': No such file or directory` on quiet days.Beginner`echo "start" > $logfile` fails with `bash: $logfile: ambiguous redirect`Intermediate`hosts[${#hosts[@]}-1]` style code fails with `bash: hosts: bad array subscript`.Intermediate