Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q7 of 15
Bash Scripting - String Operations
What is wrong with this code snippet?
var="abcabc"
echo ${var/abc}
ASyntax is correct and will print 'abc'
BReplacement string is missing after slash
CSyntax requires double slashes for replacement
DThe slash should be escaped
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax completeness

    The expression ${var/abc} is valid and deletes the first match of 'abc'.
  2. Step 2: Confirm behavior

    Nothing wrong; 'abcabc' becomes 'abc' after deleting first 'abc'. For replacement, add new string.
  3. Final Answer:

    Syntax is correct and will print 'abc' -> Option A
  4. Quick Check:

    Syntax valid, deletes first match = A [OK]
Quick Trick: Without new string after slash, deletes first match [OK]
Common Mistakes:
MISTAKES
  • Confusing deletion with syntax error
  • Assuming default replacement
  • Using wrong slash count
  • Escaping slash unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes