A systems administrator wrote a script that checks an environment variable for a specific string to enable resource creation. If that environment variable is set to the expected string, a group of resources is created. If not, it does nothing. Which snippet best meets the requirement?
if [ "$ENVIRONMENT" = "ACTIVE" ]; then buildGroup; fi
if [ "$ENVIRONMENT" -eq "ACTIVE" ]; then buildGroup; fi
while [ "$ENVIRONMENT" = "ACTIVE" ]; do buildGroup; done
This approach uses a straightforward if statement with a string comparison operator to confirm the environment variable matches the expected string. The other options use numeric comparisons, indefinite loops, or incomplete syntax, which can result in failures or unpredictable behavior.
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 purpose of an environment variable in a script?
Open an interactive chat with Bash
What does the [ ] syntax represent in shell scripting?
Open an interactive chat with Bash
Why does the '-eq' operator not work for string comparisons?