Bird
0
0

Given path="/home/user/archive.tar.gz", which expression removes the longest suffix starting with a dot, resulting in /home/user/archive?

hard🚀 Application Q9 of 15
Bash Scripting - String Operations
Given path="/home/user/archive.tar.gz", which expression removes the longest suffix starting with a dot, resulting in /home/user/archive?
A${path%.tar.gz}
B${path%.*}
C${path%%.*}
D${path%%.tar.gz}
Step-by-Step Solution
Solution:
  1. Step 1: Understand %% operator

    %% removes the longest matching suffix pattern.
  2. Step 2: Pattern .* matches dot and any characters

    Using ${path%%.*} removes from first dot to end, leaving '/home/user/archive'.
  3. Final Answer:

    ${path%%.*} -> Option C
  4. Quick Check:

    Longest suffix starting with dot removed = ${path%%.*} [OK]
Quick Trick: Use %%.* to remove longest suffix starting with dot [OK]
Common Mistakes:
MISTAKES
  • Using single % which removes shortest suffix
  • Using exact suffix pattern instead of wildcard
  • Confusing prefix and suffix removal

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes