Bird
0
0

Which statement about $var and ${var} is true in bash scripting?

hard🧠 Conceptual Q10 of 15
Bash Scripting - Variables
Which statement about $var and ${var} is true in bash scripting?
A<code>${var}</code> is required only when variable is empty
B<code>$var</code> and <code>${var}</code> always behave identically
C<code>${var}</code> allows more complex expressions and disambiguates variable names
D<code>$var</code> is deprecated and should not be used
Step-by-Step Solution
Solution:
  1. Step 1: Compare $var and ${var} usage

    $var is simple variable access; ${var} allows complex expressions and avoids ambiguity.
  2. Step 2: Evaluate each statement

    A is false because braces are not only for empty variables; C is false because behavior differs when concatenating; D is false because $var is valid and common.
  3. Final Answer:

    ${var} allows more complex expressions and disambiguates variable names -> Option C
  4. Quick Check:

    Braces add clarity and power = B [OK]
Quick Trick: Use braces for clarity and advanced variable usage [OK]
Common Mistakes:
MISTAKES
  • Thinking $var and ${var} are always same
  • Believing $var is deprecated
  • Using braces only for empty variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes