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?
while [ "$ENVIRONMENT" = "ACTIVE" ]; do buildGroup; done
if [ "$ENVIRONMENT" ]; buildGroup fi
if [ "$ENVIRONMENT" = "ACTIVE" ]; then buildGroup; fi
if [ "$ENVIRONMENT" -eq "ACTIVE" ]; then buildGroup; fi
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 an environment variable in scripting?
Open an interactive chat with Bash
Why is the `if [ "$ENVIRONMENT" = "ACTIVE" ]; then` condition correct?
Open an interactive chat with Bash
What are the key issues with the incorrect script snippets?