Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the variable 'file' exists.
Bash Scripting
if [ -e [1] ]; then echo "File exists"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the $ before the variable name inside [ ]
Using quotes incorrectly around the variable
✗ Incorrect
In bash, to check the value of a variable inside [ ], you must use $ before the variable name.
2fill in blank
mediumComplete the code to test if the variable 'num' is equal to 10 using the test command.
Bash Scripting
if test [1] -eq 10; then echo "Number is 10"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable name without $
Putting quotes around the variable name
✗ Incorrect
The test command needs the variable's value, so use $num to get it.
3fill in blank
hardFix the error in the code to correctly check if the string variable 'word' is empty.
Bash Scripting
if [ [1] = "" ]; then echo "Empty string"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable name without $
Using quotes around the variable name
✗ Incorrect
Inside [ ], use $word to get the variable's value for comparison.
4fill in blank
hardFill both blanks to check if the file stored in 'filename' is readable and writable.
Bash Scripting
if [ [1] -r [2] ]; then echo "File is readable"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable name without $
Mixing up -r and -w flags
✗ Incorrect
Use $filename to get the file name and -r to check readability inside [ ].
5fill in blank
hardFill all three blanks to create a test that checks if the variable 'count' is greater than 5 and less than 10.
Bash Scripting
if [ [1] [2] 5 ] && [ [3] -lt 10 ]; then echo "Count is between 6 and 9"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting $ before variable
Using wrong comparison operators
✗ Incorrect
Use $count to get the variable's value, -gt to check greater than, and $count again for the second test.