Challenge - 5 Problems
Test Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of test command with string comparison
What is the output of this bash script snippet?
Bash Scripting
if test "abc" = "abc"; then echo success; else echo fail; fi
Attempts:
2 left
💡 Hint
The test command checks if two strings are equal.
✗ Incorrect
The test command with '=' compares strings. Since both are "abc", the condition is true and 'success' is printed.
💻 Command Output
intermediate2:00remaining
Behavior of [ ] with numeric comparison
What will this script print?
Bash Scripting
if [ 5 -gt 3 ]; then echo yes; else echo no; fi
Attempts:
2 left
💡 Hint
The -gt operator compares numbers inside [ ].
✗ Incorrect
5 is greater than 3, so the condition is true and 'yes' is printed.
💻 Command Output
advanced2:00remaining
Effect of missing spaces in [ ] test
What error or output does this script produce?
Bash Scripting
if [5 -eq 5]; then echo ok; else echo fail; fi
Attempts:
2 left
💡 Hint
Remember that spaces are required around [ and ] in bash tests.
✗ Incorrect
Without spaces, bash treats '[5' as a command, which does not exist, causing a command not found error.
💻 Command Output
advanced2:00remaining
Difference between test and [ ] with file existence
What is the output of this script if file.txt exists?
Bash Scripting
if test -f file.txt; then echo found; else echo missing; fi
Attempts:
2 left
💡 Hint
The -f option checks if a file exists and is a regular file.
✗ Incorrect
If file.txt exists as a regular file, test -f returns true and 'found' is printed.
💻 Command Output
expert2:00remaining
Complex condition with test and [ ] combined
What does this script print if variable VAR is empty?
Bash Scripting
VAR=""; if test -z "$VAR" && [ 1 -eq 1 ]; then echo pass; else echo fail; fi
Attempts:
2 left
💡 Hint
test -z checks if a string is empty; && combines conditions.
✗ Incorrect
VAR is empty, so test -z "$VAR" is true, and [ 1 -eq 1 ] is also true, so 'pass' is printed.