Bird
0
0

In bash scripting, what does ${var:3:2} extract from the variable var?

easy🧠 Conceptual Q1 of 15
Bash Scripting - String Operations
In bash scripting, what does ${var:3:2} extract from the variable var?
AThree characters starting from the 2nd character
BTwo characters starting from the 4th character
CThe entire string from the 3rd character onward
DThe first two characters of the string
Step-by-Step Solution
Solution:
  1. Step 1: Understand substring syntax

    The syntax ${var:offset:length} extracts length characters starting at offset (0-based).
  2. Step 2: Apply to given expression

    ${var:3:2} extracts 2 characters starting from index 3 (the 4th character).
  3. Final Answer:

    Two characters starting from the 4th character -> Option B
  4. Quick Check:

    Substring extraction = Two characters from 4th char [OK]
Quick Trick: Offset counts from zero; length is how many chars to take [OK]
Common Mistakes:
MISTAKES
  • Counting offset from 1 instead of 0
  • Confusing length with offset
  • Assuming it extracts from the start

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes