Challenge - 5 Problems
String Length Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2: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}
Attempts:
2 left
💡 Hint
Count all characters including spaces.
✗ Incorrect
The variable 'text' contains "Hello World" which has 11 characters including the space. Using ${#text} returns the length of the string.
💻 Command Output
intermediate2:00remaining
What does this script output?
What will this Bash script print?
Bash Scripting
empty="" echo ${#empty}
Attempts:
2 left
💡 Hint
Check the length of an empty string.
✗ Incorrect
The variable 'empty' is set to an empty string. Its length is 0.
💻 Command Output
advanced2:00remaining
What is the output of this script with special characters?
What will this Bash script print?
Bash Scripting
special="\n\t" echo ${#special}
Attempts:
2 left
💡 Hint
Count all characters including backslashes.
✗ Incorrect
The variable 'special' contains four characters: backslash, n, backslash, t. So length is 4.
💻 Command Output
advanced2: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}
Attempts:
2 left
💡 Hint
Count all characters including the backslash and n.
✗ Incorrect
The string contains 12 characters: H e l l o \ n W o r l d (the backslash and n count as two characters).
📝 Syntax
expert2:00remaining
Which option causes a syntax error when trying to get string length?
Which of these Bash commands will cause a syntax error?
Attempts:
2 left
💡 Hint
Check the syntax for parameter expansion and arithmetic.
✗ Incorrect
Option B uses incorrect syntax: ${#var-1} is invalid because the '-' is interpreted as a subtraction but not in a valid context. The correct way to subtract would be different.