0
0
Bash Scriptingscripting~10 mins

Integer comparisons (-eq, -ne, -gt, -lt, -ge, -le) in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if variable x equals 10.

Bash Scripting
if [ "$x" [1] 10 ]; then echo "Equal"; fi
Drag options to blanks, or click blank then click option'
A-eq
B-ne
C-gt
D-lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-ne' which means 'not equal'.
Using '-gt' or '-lt' which check greater or less than.
2fill in blank
medium

Complete the code to check if variable y is greater than 5.

Bash Scripting
if [ "$y" [1] 5 ]; then echo "Greater"; fi
Drag options to blanks, or click blank then click option'
A-ne
B-gt
C-eq
D-le
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-le' which means 'less than or equal'.
Using '-eq' which means 'equal'.
3fill in blank
hard

Fix the error in the code to check if z is less than or equal to 20.

Bash Scripting
if [ "$z" [1] 20 ]; then echo "Less or equal"; fi
Drag options to blanks, or click blank then click option'
A-lt
B-ge
C-ne
D-le
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-lt' which means strictly less than.
Using '-ge' which means greater than or equal.
4fill in blank
hard

Fill both blanks to check if variable a is not equal to 0 and greater than 10.

Bash Scripting
if [ "$a" [1] 0 ] && [ "$a" [2] 10 ]; then echo "Valid"; fi
Drag options to blanks, or click blank then click option'
A-ne
B-eq
C-gt
D-lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-eq' instead of '-ne' for not equal.
Using '-lt' instead of '-gt' for greater than.
5fill in blank
hard

Fill all three blanks to create a condition that checks if b is greater or equal to 5, less than 15, and not equal to 10.

Bash Scripting
if [ "$b" [1] 5 ] && [ "$b" [2] 15 ] && [ "$b" [3] 10 ]; then echo "In range and valid"; fi
Drag options to blanks, or click blank then click option'
A-ge
B-lt
C-ne
D-eq
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-gt' instead of '-ge' for greater or equal.
Using '-le' instead of '-lt' for less than.
Using '-eq' instead of '-ne' for not equal.