Bird
0
0

If var is set to an empty string, what will echo ${var:-"default"} output?

easy🧠 Conceptual Q1 of 15
Bash Scripting - String Operations
If var is set to an empty string, what will echo ${var:-"default"} output?
Aempty string
Bdefault
Cvar
DAn error message
Step-by-Step Solution
Solution:
  1. Step 1: Understand the syntax

    The expression ${var:-default} returns default if var is unset or null (empty string counts as set but null).
  2. Step 2: Check the value of var

    Since var is set to an empty string (which is not null), it returns the empty string.
  3. Final Answer:

    empty string -> Option A
  4. Quick Check:

    Empty string is treated as set, so default is not used [OK]
Quick Trick: Empty string is treated as set, so default is not used [OK]
Common Mistakes:
MISTAKES
  • Assuming empty string triggers default
  • Confusing ${var:-default} with ${var-default}

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes