Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the variable name is equal to "Alice".
Bash Scripting
if [ "$name" [1] "Alice" ]; then echo "Hello, Alice!" fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '=' when checking for equality.
Using '-z' or '-n' which check string length, not equality.
✗ Incorrect
The operator '=' checks if two strings are equal in bash test expressions.
2fill in blank
mediumComplete the code to check if the variable input is not empty.
Bash Scripting
if [ [1] "$input" ]; then echo "Input received." fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-z' which checks if the string is empty.
Using '=' or '!=' which compare strings but don't check emptiness.
✗ Incorrect
The '-n' operator returns true if the string length is not zero (not empty).
3fill in blank
hardFix the error in the code to check if var is empty.
Bash Scripting
if [ [1] "$var" ]; then echo "Variable is empty." fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' or '!=' without a second string to compare.
Using '-n' which checks for non-empty strings.
✗ Incorrect
The '-z' operator returns true if the string length is zero (empty).
4fill in blank
hardFill both blanks to check if user is not "admin" and is not empty.
Bash Scripting
if [ "$user" [1] "admin" ] && [ [2] "$user" ]; then echo "Access denied." fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '!=' for inequality.
Using '-z' instead of '-n' to check non-empty string.
✗ Incorrect
Use '!=' to check user is not 'admin' and '-n' to check user is not empty.
5fill in blank
hardFill all three blanks to create a condition that checks if file is empty or equals "default.txt".
Bash Scripting
if [ [1] "$file" ] || [ "$file" [2] [3] ]; then echo "Using default file." fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '=' for equality check.
Not quoting the string "default.txt".
✗ Incorrect
Use '-z' to check if file is empty, '=' to check equality, and '"default.txt"' as the string to compare.