Bird
0
0

What will be the output of this script?

medium📝 Command Output Q4 of 15
Bash Scripting - String Operations
What will be the output of this script?
str="abc def"
echo ${#str}
A7
B6
C3
D8
Step-by-Step Solution
Solution:
  1. Step 1: Count characters including spaces

    The string "abc def" has 7 characters: a, b, c, space, d, e, f.
  2. Step 2: ${#str} returns total character count

    The expression returns 7 because spaces count as characters.
  3. Final Answer:

    7 -> Option A
  4. Quick Check:

    Count includes spaces = 7 [OK]
Quick Trick: Spaces count as characters in ${#var} length [OK]
Common Mistakes:
MISTAKES
  • Ignoring spaces in length count
  • Counting words instead of characters
  • Assuming length excludes spaces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes