Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the variable 'num' is equal to 10.
Bash Scripting
if [ $num [1] 10 ]; then echo "Number is ten" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' or '==' which are for strings, not numbers.
Forgetting spaces around brackets and operators.
✗ Incorrect
In bash, to compare integers, use -eq inside the test brackets.
2fill in blank
mediumComplete the code to add an elif branch that checks if 'num' is greater than 10.
Bash Scripting
if [ $num -eq 10 ]; then echo "Number is ten" elif [ $num [1] 10 ]; then echo "Number is greater than ten" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-lt' which means 'less than'.
Using '==' which is for strings, not numbers.
✗ Incorrect
The operator -gt means 'greater than' for integers in bash.
3fill in blank
hardFix the error in the else branch syntax.
Bash Scripting
if [ $num -eq 10 ]; then echo "Number is ten" elif [ $num -gt 10 ]; then echo "Number is greater than ten" [1] echo "Number is less than ten" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Writing 'elif' without a condition.
Using 'then' alone without 'else'.
✗ Incorrect
The else branch starts with the keyword else without any condition.
4fill in blank
hardFill both blanks to correctly compare a string variable 'color' with 'red' and 'blue'.
Bash Scripting
if [ "$color" [1] "red" ]; then echo "Color is red" elif [ "$color" [2] "blue" ]; then echo "Color is blue" else echo "Color is something else" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-eq' which is for numbers.
Using '!=' when checking for equality.
✗ Incorrect
For string comparison in bash, = and == are valid inside [ ].
5fill in blank
hardFill all three blanks to create a nested if-elif-else that checks if 'score' is above 90, above 75, or else.
Bash Scripting
if [ $score [1] 90 ]; then echo "Grade A" elif [ $score [2] 75 ]; then echo "Grade B" [3] echo "Grade C" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'else' with a condition.
Mixing string and numeric operators.
✗ Incorrect
Use -gt for 'greater than', -ge for 'greater or equal', and else for the fallback case.