Challenge - 5 Problems
String Comparison 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 snippet?
Consider the following Bash code:
str="hello" if [ "$str" = "hello" ]; then echo "Match" else echo "No match" fiWhat will be printed when this script runs?
Bash Scripting
str="hello" if [ "$str" = "hello" ]; then echo "Match" else echo "No match" fi
Attempts:
2 left
💡 Hint
Check how string equality is tested in Bash with single brackets.
✗ Incorrect
The test [ "$str" = "hello" ] checks if the variable str equals the string "hello". Since it does, the script prints "Match".
💻 Command Output
intermediate2:00remaining
What does this Bash condition check?
What is the output of this Bash snippet?
str="" if [ -z "$str" ]; then echo "Empty" else echo "Not empty" fi
Bash Scripting
str="" if [ -z "$str" ]; then echo "Empty" else echo "Not empty" fi
Attempts:
2 left
💡 Hint
The -z test checks if a string is empty.
✗ Incorrect
The -z operator returns true if the string is empty. Since str is empty, it prints "Empty".
💻 Command Output
advanced2:00remaining
What is the output of this Bash script with string inequality?
Analyze this Bash code:
str="world" if [ "$str" != "hello" ]; then echo "Different" else echo "Same" fiWhat will it print?
Bash Scripting
str="world" if [ "$str" != "hello" ]; then echo "Different" else echo "Same" fi
Attempts:
2 left
💡 Hint
The != operator checks if strings are not equal.
✗ Incorrect
Since "world" is not equal to "hello", the condition is true and it prints "Different".
💻 Command Output
advanced2:00remaining
What happens when using -n with a non-empty string?
What is the output of this Bash snippet?
str="text" if [ -n "$str" ]; then echo "Has content" else echo "Empty" fi
Bash Scripting
str="text" if [ -n "$str" ]; then echo "Has content" else echo "Empty" fi
Attempts:
2 left
💡 Hint
The -n test checks if a string is not empty.
✗ Incorrect
The -n operator returns true if the string is not empty. Since str contains "text", it prints "Has content".
💻 Command Output
expert3:00remaining
What is the output of this Bash script with multiple string tests?
Consider this Bash script:
str1="" str2="data" if [ -z "$str1" ] && [ "$str2" = "data" ]; then echo "Condition met" else echo "Condition not met" fiWhat will it print?
Bash Scripting
str1="" str2="data" if [ -z "$str1" ] && [ "$str2" = "data" ]; then echo "Condition met" else echo "Condition not met" fi
Attempts:
2 left
💡 Hint
Both conditions must be true for the && operator to pass.
✗ Incorrect
str1 is empty, so -z "$str1" is true. str2 equals "data", so "$str2" = "data" is true. Both true means the script prints "Condition met".