Bird
0
0

If the variable name is unset, what will echo ${name:-"Guest"} print?

easy🧠 Conceptual Q2 of 15
Bash Scripting - String Operations
If the variable name is unset, what will echo ${name:-"Guest"} print?
Aname
BGuest
CAn empty line
DError message
Step-by-Step Solution
Solution:
  1. Step 1: Check if variable is unset

    The variable name is unset, so it has no value.
  2. Step 2: Apply default value with :-

    The expression ${name:-"Guest"} returns "Guest" when name is unset.
  3. Final Answer:

    Guest -> Option B
  4. Quick Check:

    Unset variable uses default [OK]
Quick Trick: Unset variable triggers default with :- [OK]
Common Mistakes:
MISTAKES
  • Expecting variable name printed literally
  • Confusing :- with :+
  • Assuming empty output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes