Bird
0
0

What effect does enabling set -u have on variable usage in a bash script?

easy🧠 Conceptual Q1 of 15
Bash Scripting - Error Handling
What effect does enabling set -u have on variable usage in a bash script?
AIt converts all variables to read-only
BIt automatically initializes unset variables to an empty string
CIt disables variable expansion entirely
DIt causes the script to exit with an error if an unset variable is referenced
Step-by-Step Solution
Solution:
  1. Step 1: Understand set -u

    This option treats any reference to an unset variable as an error.
  2. Step 2: Effect on script execution

    The script will terminate immediately if it tries to use a variable that has not been defined.
  3. Final Answer:

    It causes the script to exit with an error if an unset variable is referenced -> Option D
  4. Quick Check:

    Referencing unset variables triggers errors [OK]
Quick Trick: Unset variables cause errors with set -u enabled [OK]
Common Mistakes:
MISTAKES
  • Assuming unset variables default to empty strings
  • Thinking set -u disables variable expansion
  • Believing set -u makes variables read-only

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes