Bird
0
0

You have a date string date="2024-06-15". Which command extracts the month part ("06") using substring extraction?

hard🚀 Application Q15 of 15
Bash Scripting - String Operations
You have a date string date="2024-06-15". Which command extracts the month part ("06") using substring extraction?
A${date:3:2}
B${date:6:2}
C${date:4:2}
D${date:5:2}
Step-by-Step Solution
Solution:
  1. Step 1: Locate month position in date string

    The string is "2024-06-15". Counting from 0: 2(0) 0(1) 2(2) 4(3) -(4) 0(5) 6(6) -(7) 1(8) 5(9). Month starts at index 5.
  2. Step 2: Extract 2 characters starting at index 5

    Using ${date:5:2} extracts "06" which is the month.
  3. Final Answer:

    ${date:5:2} -> Option D
  4. Quick Check:

    Month = substring at 5 length 2 [OK]
Quick Trick: Count chars from zero, dash counts as char [OK]
Common Mistakes:
MISTAKES
  • Starting count at 1 instead of 0
  • Extracting wrong substring length
  • Confusing day and month positions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes