Using POSIX test syntax, check whether $MODE equals prod.
Which condition is appropriate?
The test operator = performs a string comparison; quote variable expansions to preserve argument structure.
Detailed explanation
[ "$MODE" -eq prod ]Incorrect. -eq is an integer comparison operator.
Incorrect. -eq is an integer comparison operator.
[ "$MODE" = prod ]Correct. = tests string equality in test syntax.
Correct. = tests string equality in test syntax.
[ "$MODE" -f prod ]Incorrect. -f tests whether a path is a regular file.
Incorrect. -f tests whether a path is a regular file.
[ "$MODE" -gt prod ]Incorrect. -gt is an integer greater-than comparison.
Incorrect. -gt is an integer greater-than comparison.
Try it yourself
An example you can run in a temporary verification environment.
MODE=prod; if [ "$MODE" = prod ]; then printf equal; fiExpected result
equalKey points
- = compares strings
- -eq compares integers
- Quote variables
Notes
- Environment: POSIX互換test / GNU Bash 5.2
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.