0
0
Bash Scriptingscripting~20 mins

[[ ]] extended test in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
[[ ]] Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Output of [[ ]] with string comparison
What is the output of the following bash script snippet?
Bash Scripting
str1="hello"
str2="hello"
if [[ $str1 == $str2 ]]; then
  echo "Match"
else
  echo "No Match"
fi
ASyntax Error
BNo Match
CMatch
DNo output
Attempts:
2 left
💡 Hint
The [[ ]] test compares strings for equality.
💻 Command Output
intermediate
1:30remaining
Numeric comparison with [[ ]]
What will this script output?
Bash Scripting
num=5
if [[ $num -gt 3 ]]; then
  echo "Greater"
else
  echo "Smaller or equal"
fi
ASyntax Error
BGreater
CSmaller or equal
DNo output
Attempts:
2 left
💡 Hint
Use -gt for numeric greater than comparison inside [[ ]].
💻 Command Output
advanced
1:30remaining
Testing file existence with [[ ]]
What is the output of this script if the file /etc/passwd exists?
Bash Scripting
if [[ -f /etc/passwd ]]; then
  echo "File exists"
else
  echo "File missing"
fi
AFile exists
BFile missing
CSyntax Error
DNo output
Attempts:
2 left
💡 Hint
The -f option tests if a file exists and is a regular file.
💻 Command Output
advanced
1:30remaining
Logical AND with [[ ]]
What will this script output?
Bash Scripting
a=10
b=20
if [[ $a -lt 15 && $b -gt 15 ]]; then
  echo "Both true"
else
  echo "Condition failed"
fi
ABoth true
BCondition failed
CSyntax Error
DNo output
Attempts:
2 left
💡 Hint
Use && inside [[ ]] for logical AND.
💻 Command Output
expert
2:00remaining
Complex string pattern matching with [[ ]]
What is the output of this script?
Bash Scripting
filename="report2024.txt"
if [[ $filename == report[0-9][0-9][0-9][0-9].txt ]]; then
  echo "Pattern matched"
else
  echo "No match"
fi
ASyntax Error
BNo match
CNo output
DPattern matched
Attempts:
2 left
💡 Hint
The [[ ]] supports pattern matching with glob patterns like [0-9].