Bird
0
0

In bash scripting, what value does ${#var} provide when var="OpenAI"?

easy🧠 Conceptual Q1 of 15
Bash Scripting - String Operations
In bash scripting, what value does ${#var} provide when var="OpenAI"?
AThe number of words in <code>var</code>
BThe ASCII value of the first character in <code>var</code>
CThe number of characters in the string stored in <code>var</code>
DThe memory address of the variable <code>var</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand the expression

    ${#var} returns the length of the string stored in var.
  2. Step 2: Apply to the given string

    For var="OpenAI", the string length is 6.
  3. Final Answer:

    6 -> Option C
  4. Quick Check:

    Counting characters in "OpenAI" gives 6 [OK]
Quick Trick: Use ${#var} to get string length directly [OK]
Common Mistakes:
MISTAKES
  • Confusing string length with ASCII values
  • Assuming it counts words instead of characters
  • Thinking it returns variable memory address

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes