Bird
0
0

Consider the script snippet:

medium📝 Debug Q14 of 15
Bash Scripting - String Operations
Consider the script snippet:
var="abc123abc456"
echo ${var##abc*}
It outputs an empty line. Why?
ABecause the pattern is invalid and causes an error
BBecause <code>abc*</code> matches the entire string as shortest prefix
CBecause <code>abc*</code> matches the longest prefix, so nothing remains
DBecause the variable is empty
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the pattern abc*

    The pattern abc* matches 'abc' followed by zero or more any characters.
  2. Step 2: Understand longest prefix removal

    With ##, it removes the longest matching prefix. The * matches greedily as many characters as possible after 'abc', so the match covers the entire string.
  3. Final Answer:

    Because abc* matches the longest prefix, so nothing remains -> Option C
  4. Quick Check:

    Longest prefix with ## + greedy * = B [OK]
Quick Trick: Wildcard * matches greedily with longest prefix ## [OK]
Common Mistakes:
MISTAKES
  • Confusing ## (longest) with # (shortest)
  • Underestimating greedy nature of * in longest match
  • Assuming pattern causes error or variable is empty

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes