Bird
0
0

Which of the following is the correct syntax to remove the shortest suffix '.log' from the variable file in Bash?

easy📝 Syntax Q12 of 15
Bash Scripting - String Operations
Which of the following is the correct syntax to remove the shortest suffix '.log' from the variable file in Bash?
A${file%%.log}
B${file%.log}
C${file#log}
D${file%log}
Step-by-Step Solution
Solution:
  1. Step 1: Identify suffix removal syntax

    To remove the shortest suffix matching a pattern, use single % with the pattern including the dot: %.log
  2. Step 2: Check each option

    A uses %% which removes longest suffix, C uses # which removes prefix, D misses the dot before 'log'. Only B is correct syntax.
  3. Final Answer:

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

    Use single % with pattern for shortest suffix removal [OK]
Quick Trick: Use single % with exact suffix pattern to remove shortest suffix [OK]
Common Mistakes:
MISTAKES
  • Using %% instead of %
  • Confusing % with # for prefix removal
  • Omitting the dot in the pattern

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes