Bird
0
0

Which of the following expressions removes the shortest suffix '.bak' from the variable file in Bash?

easy🧠 Conceptual Q2 of 15
Bash Scripting - String Operations
Which of the following expressions removes the shortest suffix '.bak' from the variable file in Bash?
A${file%%.bak}
B${file%.bak}
C${file#bak}
D${file%bak}
Step-by-Step Solution
Solution:
  1. Step 1: Identify suffix removal syntax

    The % operator removes the shortest suffix matching the pattern; %% removes the longest suffix.
  2. Step 2: Match the pattern '.bak'

    To remove '.bak' exactly as suffix, use ${file%.bak}.
  3. Final Answer:

    ${file%.bak} -> Option B
  4. Quick Check:

    Shortest suffix '.bak' removal = ${file%.bak} [OK]
Quick Trick: Use single % to remove shortest suffix pattern [OK]
Common Mistakes:
MISTAKES
  • Using %% which removes longest suffix
  • Using # which removes prefix instead of suffix
  • Omitting the dot in pattern causing wrong removal

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes