Bird
0
0

Which of the following is the correct syntax to extract 4 characters starting at position 1 from variable text?

easy📝 Syntax Q12 of 15
Bash Scripting - String Operations
Which of the following is the correct syntax to extract 4 characters starting at position 1 from variable text?
A${text:1:4}
B${text:4:1}
C${text:1-4}
D${text:1,4}
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct substring syntax

    The correct syntax uses colon separators: ${var:offset:length}.
  2. Step 2: Match syntax to options

    ${text:1:4} matches this exactly with offset 1 and length 4. Others use invalid separators or wrong order.
  3. Final Answer:

    ${text:1:4} -> Option A
  4. Quick Check:

    Correct syntax uses colons [OK]
Quick Trick: Use colons, not commas or dashes [OK]
Common Mistakes:
MISTAKES
  • Using commas or dashes instead of colons
  • Swapping offset and length
  • Missing braces around variable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes