Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the variable num is equal to 5.
Bash Scripting
if [ "$num" [1] 5 ]; then echo "Number is five" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string comparison operators like '=' or '==' for numbers.
Forgetting spaces around brackets and operators.
✗ Incorrect
In bash, to compare integers inside [ ], use -eq for equality.
2fill in blank
mediumComplete the code to check if the file myfile.txt exists.
Bash Scripting
if [1] myfile.txt; then echo "File exists" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
-d which checks only directories.Using
-s which checks if file is not empty.✗ Incorrect
test -e checks if a file or directory exists.
3fill in blank
hardFix the error in the if statement to correctly check if count is greater than 10.
Bash Scripting
if [ $count [1] 10 ]; then echo "Count is large" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' inside single brackets which is a string comparison and needs escaping.
Using '==' which is for string equality.
✗ Incorrect
For numeric comparisons in bash, use -gt for 'greater than'.
4fill in blank
hardFill both blanks to check if the variable word is not empty and equals "hello".
Bash Scripting
if [ -n [1] ] && [ [2] = "hello" ]; then echo "Greeting detected" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
-z which checks for empty string.Not using the variable with a $ sign.
✗ Incorrect
-n $word checks if word is not empty, and $word = "hello" checks string equality.
5fill in blank
hardFill all three blanks to check if num is between 1 and 10 inclusive.
Bash Scripting
if [ [1] -ge 1 ] && [ [2] [3] 10 ]; then echo "Number is between 1 and 10" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string comparison operators instead of numeric ones.
Using
-lt instead of -le for the upper bound.✗ Incorrect
Use $num -ge 1 to check greater or equal 1, and $num -le 10 to check less or equal 10.