Bird
0
0

Given the Bash code:

medium📝 Command Output Q13 of 15
Bash Scripting - String Operations
Given the Bash code:
filename="report.final.txt"
echo ${filename%.txt}

What is the output?
Areport.final.tx
Breport
Creport.final.txt
Dreport.final
Step-by-Step Solution
Solution:
  1. Step 1: Understand the variable value

    The variable filename contains 'report.final.txt'.
  2. Step 2: Apply ${filename%.txt}

    This removes the shortest suffix matching '.txt' from the end, leaving 'report.final'.
  3. Final Answer:

    report.final -> Option D
  4. Quick Check:

    Suffix '.txt' removed once from end [OK]
Quick Trick: Remove suffix by matching pattern at string end with % [OK]
Common Mistakes:
MISTAKES
  • Removing more than '.txt' suffix
  • Confusing prefix removal with suffix removal
  • Expecting the full string unchanged

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes