Bird
0
0

What does the Bash expression ${var#pattern} do?

easy🧠 Conceptual Q11 of 15
Bash Scripting - String Operations
What does the Bash expression ${var#pattern} do?
ARemoves the shortest matching prefix pattern from the variable's value
BRemoves the longest matching suffix pattern from the variable's value
CRemoves the shortest matching suffix pattern from the variable's value
DRemoves the longest matching prefix pattern from the variable's value
Step-by-Step Solution
Solution:
  1. Step 1: Understand the syntax

    The syntax ${var#pattern} is used in Bash to remove a prefix pattern from the start of the variable's value.
  2. Step 2: Identify shortest prefix removal

    The single # removes the shortest matching prefix, unlike ## which removes the longest.
  3. Final Answer:

    Removes the shortest matching prefix pattern from the variable's value -> Option A
  4. Quick Check:

    Prefix removal = shortest match = A [OK]
Quick Trick: Single # removes shortest prefix, double ## removes longest [OK]
Common Mistakes:
MISTAKES
  • Confusing # with ## for prefix length
  • Mixing prefix removal with suffix removal
  • Thinking it removes suffix instead of prefix

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes