Bird
0
0

Given text="banana bandana", what is the output of echo ${text/ana/123}?

medium📝 Command Output Q4 of 15
Bash Scripting - String Operations
Given text="banana bandana", what is the output of echo ${text/ana/123}?
Ab123na band123na
Bb123na b123dana
Cbanana bandana
Db123na bandana
Step-by-Step Solution
Solution:
  1. Step 1: Understand replacement of first occurrence

    The expression replaces only the first 'ana' in 'banana bandana'. The first 'ana' appears in 'banana' at position 2.
  2. Step 2: Apply replacement

    Replacing first 'ana' with '123' changes 'banana' to 'b123na'. The rest remains unchanged.
  3. Final Answer:

    b123na bandana -> Option D
  4. Quick Check:

    First occurrence replaced only = A [OK]
Quick Trick: Only first match replaced with single slash [OK]
Common Mistakes:
MISTAKES
  • Replacing all occurrences
  • No replacement happens
  • Replacing wrong substring
  • Misreading variable content

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes