Bird
0
0

In Bash, what happens if you try to use a variable that has not been set or assigned a value?

hard📝 Conceptual Q10 of 15
Linux CLI - Linux Basics and Terminal
In Bash, what happens if you try to use a variable that has not been set or assigned a value?
AThe shell throws a syntax error and stops
BThe variable expands to an empty string
CThe shell assigns it a default value of zero
DThe shell prompts the user to enter a value
Step-by-Step Solution
Solution:
  1. Step 1: Recall Bash variable behavior

    In Bash, if a variable is not set, referencing it returns an empty string by default.
  2. Step 2: Check other options

    Bash does not throw syntax errors for unset variables, nor assigns zero or prompts user automatically.
  3. Final Answer:

    The variable expands to an empty string -> Option B
  4. Quick Check:

    Unset variable expansion = empty string [OK]
Quick Trick: Unset variables expand to empty strings unless set -u used [OK]
Common Mistakes:
  • Expecting errors for unset variables
  • Assuming default zero value
  • Thinking shell prompts for input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes