Bird
0
0

Given filename="backup_20240615.tar.gz", how do you extract the date part (8 digits) using substring extraction?

hard🚀 Application Q9 of 15
Bash Scripting - String Operations
Given filename="backup_20240615.tar.gz", how do you extract the date part (8 digits) using substring extraction?
A${filename:7:8}
B${filename:6:8}
C${filename:7:7}
D${filename:8:8}
Step-by-Step Solution
Solution:
  1. Step 1: Locate date substring

    Date starts after "backup_" which is 7 characters, so offset is 7.
  2. Step 2: Extract 8 characters for date

    Use ${filename:7:8} to get 8 digits of date.
  3. Final Answer:

    ${filename:7:8} -> Option A
  4. Quick Check:

    Offset 7 length 8 extracts date correctly [OK]
Quick Trick: Count offset carefully; length matches date digits [OK]
Common Mistakes:
MISTAKES
  • Off by one error in offset
  • Wrong length for date
  • Extracting extra characters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes