0
0
Bash Scriptingscripting~20 mins

test command and [ ] syntax in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Test Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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
Asyntax error
Bsuccess
Ctest: command not found
Dfail
Attempts:
2 left
💡 Hint
The test command checks if two strings are equal.
💻 Command Output
intermediate
2:00remaining
Behavior of [ ] with numeric comparison
What will this script print?
Bash Scripting
if [ 5 -gt 3 ]; then echo yes; else echo no; fi
Ayes
Bno
Csyntax error
Dcommand not found
Attempts:
2 left
💡 Hint
The -gt operator compares numbers inside [ ].
💻 Command Output
advanced
2: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
Afail
Bsyntax error
Cok
Dbash: [5: command not found
Attempts:
2 left
💡 Hint
Remember that spaces are required around [ and ] in bash tests.
💻 Command Output
advanced
2: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
Asyntax error
Bmissing
Cfound
Dcommand not found
Attempts:
2 left
💡 Hint
The -f option checks if a file exists and is a regular file.
💻 Command Output
expert
2: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
Apass
Bfail
Csyntax error
Dcommand not found
Attempts:
2 left
💡 Hint
test -z checks if a string is empty; && combines conditions.