Bird
0
0

Given var="abc123abc456", what does echo ${var#abc} output?

easy🧠 Conceptual Q2 of 15
Bash Scripting - String Operations
Given var="abc123abc456", what does echo ${var#abc} output?
A123abc456abc
B123abc456
Cabc123abc456
D456
Step-by-Step Solution
Solution:
  1. Step 1: Identify the shortest prefix matching 'abc'

    The variable starts with 'abc', so the shortest prefix 'abc' is removed.
  2. Step 2: Remove the prefix and output the rest

    Removing 'abc' leaves '123abc456'.
  3. Final Answer:

    123abc456 -> Option B
  4. Quick Check:

    Prefix 'abc' removed once = 123abc456 [OK]
Quick Trick: Removes only the first matching prefix, not all occurrences [OK]
Common Mistakes:
MISTAKES
  • Removing all 'abc' occurrences instead of just prefix
  • Confusing prefix removal with suffix removal
  • Expecting output unchanged if prefix matches

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes