Bird
0
0

Given filename="data_backup_2023.tar.gz", what does echo ${filename:5:7} output?

medium📝 Command Output Q5 of 15
Bash Scripting - String Operations
Given filename="data_backup_2023.tar.gz", what does echo ${filename:5:7} output?
Adata_ba
Bbackup
Cbackup_2
Dbackup_
Step-by-Step Solution
Solution:
  1. Step 1: Identify offset and length

    Offset is 5, length is 7, so extract 7 characters starting at index 5.
  2. Step 2: Extract substring from "data_backup_2023.tar.gz"

    Characters at positions 5 to 11 are 'b', 'a', 'c', 'k', 'u', 'p', '_', forming "backup_".
  3. Final Answer:

    backup_ -> Option D
  4. Quick Check:

    Substring from index 5 length 7 = "backup_" [OK]
Quick Trick: Count offset from zero; length is number of chars to extract [OK]
Common Mistakes:
MISTAKES
  • Extracting fewer characters than length
  • Confusing offset with length
  • Including extra characters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes