Bird
0
0

What will be the output of the following Bash code?

medium📝 Command Output Q5 of 15
Bash Scripting - String Operations
What will be the output of the following Bash code?
file="document.final.backup"
echo ${file%.backup}
Adocument.final
Bdocument.final.backup
Cdocument.final.back
Ddocument.final.backup.backup
Step-by-Step Solution
Solution:
  1. Step 1: Identify the suffix pattern

    The pattern '.backup' matches the suffix to remove.
  2. Step 2: Remove shortest suffix '.backup'

    Removing '.backup' from 'document.final.backup' leaves 'document.final'.
  3. Final Answer:

    document.final -> Option A
  4. Quick Check:

    Suffix '.backup' removed = document.final [OK]
Quick Trick: Suffix removal removes exact matching pattern at end [OK]
Common Mistakes:
MISTAKES
  • Removing partial suffix incorrectly
  • Expecting prefix removal
  • Using %% which removes longest suffix

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes