A systems engineer is hardening a deployment script. The script should execute a protected configuration block only when the variable $MODE has the exact value config. Because $MODE might contain whitespace or wildcard characters in other circumstances, the comparison must avoid word-splitting or pathname expansion. Which Bash test expression should be placed inside the if statement to meet these requirements?
The expression [[ "$MODE" == "config" ]] performs a literal string comparison inside Bash's double-bracket conditional. Within [[ … ]] Bash suppresses word splitting and pathname expansion , so the test is safe even if $MODE contains spaces or globs. [[ "$MODE" -eq "config" ]] attempts an arithmetic comparison, which is intended for integers . [ $MODE = config ] leaves the variable unquoted; if $MODE were empty, contained spaces, or expanded to a wildcard, the test could break or mis-match. (( $MODE == config )) uses arithmetic evaluation and therefore also treats the operands numerically, not as strings.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the difference between [ ] and [[ ]] in shell scripting?
Open an interactive chat with Bash
Why is '==' used for string comparison instead of '-eq'?
Open an interactive chat with Bash
When should quotes be used around variables in conditionals?