0
0
Bash Scriptingscripting~20 mins

String length (${#var}) in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Length Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Bash script?
Consider the following Bash script. What will it print?
Bash Scripting
text="Hello World"
echo ${#text}
A11
B10
CError: invalid syntax
D12
Attempts:
2 left
💡 Hint
Count all characters including spaces.
💻 Command Output
intermediate
2:00remaining
What does this script output?
What will this Bash script print?
Bash Scripting
empty=""
echo ${#empty}
Anull
B1
CError: variable not set
D0
Attempts:
2 left
💡 Hint
Check the length of an empty string.
💻 Command Output
advanced
2:00remaining
What is the output of this script with special characters?
What will this Bash script print?
Bash Scripting
special="\n\t"
echo ${#special}
A4
B2
C1
DError: invalid escape sequence
Attempts:
2 left
💡 Hint
Count all characters including backslashes.
💻 Command Output
advanced
2:00remaining
What is the output of this script with a multi-line string?
What will this Bash script print?
Bash Scripting
multi="Hello\nWorld"
echo ${#multi}
A11
B10
C12
DError: invalid string
Attempts:
2 left
💡 Hint
Count all characters including the backslash and n.
📝 Syntax
expert
2:00remaining
Which option causes a syntax error when trying to get string length?
Which of these Bash commands will cause a syntax error?
Aecho ${#var}
Becho ${#var-1}
Cecho ${#var:0}
Decho ${#var[0]}
Attempts:
2 left
💡 Hint
Check the syntax for parameter expansion and arithmetic.