Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q14 of 15
Bash Scripting - String Operations
What is wrong with this code snippet?
var="hello world"
echo ${var:5,3}
AOffset 5 is out of range
BLength 3 is too large
CComma is invalid separator; should use colon
DVariable name is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check substring syntax

    The substring syntax requires colons between offset and length, not commas.
  2. Step 2: Identify error in code

    The code uses a comma ${var:5,3} which is invalid and causes a syntax error.
  3. Final Answer:

    Comma is invalid separator; should use colon -> Option C
  4. Quick Check:

    Use colons, not commas [OK]
Quick Trick: Use colons between offset and length [OK]
Common Mistakes:
MISTAKES
  • Using commas instead of colons
  • Assuming offset out of range causes error
  • Misnaming variable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes