Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q6 of 15
Bash Scripting - String Operations
What is wrong with this code snippet?
text="hello world"
echo ${text/world}
AMissing replacement string after slash
BVariable name is invalid
CSyntax is correct and will print 'hello '
DShould use double slashes for replacement
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the syntax

    The expression ${text/world} is valid bash syntax that deletes the first match of 'world'.
  2. Step 2: Understand the behavior

    Nothing is wrong; it prints 'hello ' by removing 'world'. For replacement, include a new string.
  3. Final Answer:

    Syntax is correct and will print 'hello ' -> Option C
  4. Quick Check:

    Syntax valid, deletes first match = A [OK]
Quick Trick: Without new string, match is deleted [OK]
Common Mistakes:
MISTAKES
  • Confusing deletion with replacement error
  • Using invalid variable names
  • Assuming default replacement
  • Confusing with substring removal

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes