Interview Prep/Shell Scripting/Troubleshooting: quoting, expansion and tool-input bugs

`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.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: quoting, expansion and tool-input bugs