Bird
0
0

You want to unset all variables starting with temp in a script. Which approach works best?

hard🚀 Application Q8 of 15
Bash Scripting - Variables
You want to unset all variables starting with temp in a script. Which approach works best?
AUse <code>unset temp*</code> directly
BUse a loop with <code>unset</code> on each variable matching <code>temp*</code>
CUse <code>unset $temp*</code>
DUnset cannot be used with patterns
Step-by-Step Solution
Solution:
  1. Step 1: Understand unset and patterns

    unset does not expand wildcards by itself.
  2. Step 2: Use a loop to find and unset variables

    Looping over variable names matching temp* and unsetting each works correctly.
  3. Final Answer:

    Use a loop with unset on each variable matching temp* -> Option B
  4. Quick Check:

    Unset needs explicit variable names, use loop for patterns [OK]
Quick Trick: Unset wildcards via loop, not direct pattern [OK]
Common Mistakes:
MISTAKES
  • Trying to unset with wildcard directly
  • Using $ with wildcard incorrectly
  • Assuming unset supports globbing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes