Bird
0
0

Given var="folder/subfolder/file.txt", what is the output of echo ${var#*/}?

medium📝 Command Output Q13 of 15
Bash Scripting - String Operations
Given var="folder/subfolder/file.txt", what is the output of echo ${var#*/}?
Afolder/subfolder/file.txt
Bsubfolder/file.txt
Cfile.txt
Dfolder
Step-by-Step Solution
Solution:
  1. Step 1: Understand the pattern */

    The pattern */ matches the shortest prefix ending with a slash.
  2. Step 2: Remove shortest prefix matching */

    From "folder/subfolder/file.txt", the shortest prefix matching */ is "folder/". Removing it leaves "subfolder/file.txt".
  3. Final Answer:

    subfolder/file.txt -> Option B
  4. Quick Check:

    Remove shortest prefix ending with / = subfolder/file.txt [OK]
Quick Trick: Pattern */ removes up to first slash [OK]
Common Mistakes:
MISTAKES
  • Removing longest prefix with ## instead of #
  • Expecting only filename instead of subfolder/file.txt
  • Confusing prefix removal with suffix removal

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes