Bird
0
0

What does the expression ${#var} do in a bash script?

easy🧠 Conceptual Q11 of 15
Bash Scripting - String Operations
What does the expression ${#var} do in a bash script?
AIt converts the variable <code>var</code> to uppercase.
BIt returns the value of the variable <code>var</code>.
CIt counts the number of words in the variable <code>var</code>.
DIt returns the length of the string stored in the variable <code>var</code>.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the syntax ${#var}

    This syntax in bash returns the length of the string stored in the variable var.
  2. Step 2: Differentiate from other operations

    It does not return the value itself, count words, or change case. It specifically counts characters.
  3. Final Answer:

    It returns the length of the string stored in the variable var. -> Option D
  4. Quick Check:

    Length of string = ${#var} [OK]
Quick Trick: Remember: ${#var} counts characters in var [OK]
Common Mistakes:
MISTAKES
  • Confusing ${#var} with $var (value of variable)
  • Thinking it counts words instead of characters
  • Assuming it changes the string content

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes