Bird
0
0

Why does this code produce no output?

medium📝 Debug Q7 of 15
Bash Scripting - String Operations
Why does this code produce no output?
var="file."
echo ${var#*.}
ABecause the pattern '*.' does not match any prefix
BBecause the variable is empty
CBecause the pattern '*.' matches the entire string and removes all
DBecause the pattern '*.' is invalid syntax
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the pattern '*.'

    The pattern '*.' matches the shortest prefix ending with '.'. Here, the entire 'file.' matches.
  2. Step 2: Remove the matched prefix

    Removing the entire string leaves nothing, so no output.
  3. Final Answer:

    Because the pattern '*.' matches the entire string and removes all -> Option C
  4. Quick Check:

    Pattern '*.' matches entire 'file.', output empty [OK]
Quick Trick: Pattern can remove entire string if it matches full prefix [OK]
Common Mistakes:
MISTAKES
  • Assuming variable is empty
  • Thinking pattern is invalid
  • Confusing suffix removal with prefix removal

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes