Bird
0
0

What will be the output of the following bash script?

medium📝 Command Output Q13 of 15
Bash Scripting - String Operations
What will be the output of the following bash script?
text="Hello World"
echo ${#text}
A11
BError
C12
D10
Step-by-Step Solution
Solution:
  1. Step 1: Count characters in the string "Hello World"

    The string has 11 characters: 5 letters in "Hello", 1 space, and 5 letters in "World".
  2. Step 2: Understand ${#text} returns string length

    The command echo ${#text} prints the length, which is 11.
  3. Final Answer:

    11 -> Option A
  4. Quick Check:

    Length of "Hello World" = 11 [OK]
Quick Trick: Count spaces too when using ${#var} [OK]
Common Mistakes:
MISTAKES
  • Ignoring spaces in length count
  • Counting words instead of characters
  • Expecting output to be string value instead of length

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes