Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the file 'data.txt' exists and is readable.
Bash Scripting
if [ -e data.txt [1] ]; then echo "File exists and is readable"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-o' instead of '-a' for AND operation.
Forgetting to include the file test after '-a'.
Using '-f' instead of '-r' when checking readability.
✗ Incorrect
The '-a' operator means AND, so '-a -r data.txt' checks if the previous condition (file exists with '-e') and the file is readable are both true.
2fill in blank
mediumComplete the code to check if the variable 'count' is either 0 or 10.
Bash Scripting
if [ "$count" -eq 0 [1] "$count" -eq 10 ]; then echo "Count is 0 or 10"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-a' which means AND instead of OR.
Using '==' which is not valid in this context.
Using '!' which negates a condition.
✗ Incorrect
The '-o' operator means OR, so it checks if either condition is true.
3fill in blank
hardFix the error in the code to check if the directory 'logs' does NOT exist.
Bash Scripting
if [ [1] -e logs ]; then echo "Logs directory missing"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-o' or '-a' which are logical AND/OR, not negation.
Using '-z' which checks for empty strings, not existence.
✗ Incorrect
The '!' operator negates the test, so '! -e logs' means the file or directory does NOT exist.
4fill in blank
hardComplete the code to check if the file 'config.cfg' exists AND is NOT empty.
Bash Scripting
if [ -e config.cfg [1] -s config.cfg ]; then echo "Config file exists and is not empty"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-o' which means OR instead of AND.
Confusing '-s' (non-empty) with empty check; '! -s' would be for empty or non-existent.
✗ Incorrect
Use '-a' for AND to combine the existence check ('-e') and the non-empty check ('-s' means size greater than zero).
5fill in blank
hardFill all three blanks to create a condition that checks if variable 'user' is NOT 'admin' AND file 'access.log' exists OR variable 'mode' equals 'debug'.
Bash Scripting
if [ ! "$user" = [1] [2] -e access.log [3] "$mode" = "debug" ]; then echo "Condition met"; fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong strings for user comparison.
Mixing up '-a' and '-o' operators.
Not quoting variables properly.
✗ Incorrect
The condition uses '!' to negate user='admin', '-a' for AND with file existence, and '-o' for OR with mode='debug'.