Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to test if the variable 'var' is equal to 'hello'.
Bash Scripting
if [[ $var [1] "hello" ]]; then echo "Match" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' inside [[ ]] instead of '=='.
Using '-eq' which is for numbers, not strings.
✗ Incorrect
In bash [[ ]] tests, '==' is used to compare strings 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 for directories only.
Using '-f' which checks for regular files but may fail if file is special.
✗ Incorrect
The '-e' operator tests if a file or directory exists.
3fill in blank
hardFix the error in the code to check if variable 'num' is greater than 10.
Bash Scripting
if [[ $num [1] 10 ]]; then echo "Greater" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' which compares strings lexicographically.
Using '-eq' which checks equality, not greater than.
✗ Incorrect
Inside [[ ]], numeric comparisons use '-gt' for greater than, not '>'.
4fill in blank
hardFill in the blank to check if variable 'word' length is greater than 3.
Bash Scripting
if [[ ${#word} [1] 3 ]]; then echo "Long word" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which compares strings, not numbers.
Using '-lt' which means less than, not greater.
✗ Incorrect
Use '-gt' to check if length is greater than 3.
5fill in blank
hardFill both blanks to check if variable 'input' is not empty and equals 'yes'.
Bash Scripting
if [[ -n $input && $input [1] [2] ]]; then echo "Confirmed" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' for equality.
Forgetting quotes around the string 'yes'.
✗ Incorrect
Use '==' to compare strings and '"yes"' as the string literal.