Recall & Review
beginner
What does the '=' operator do in bash string comparisons?
The '=' operator checks if two strings are exactly equal. It returns true if they match.
Click to reveal answer
beginner
How do you check if two strings are NOT equal in bash?
Use the '!=' operator inside a test condition. It returns true if the strings differ.
Click to reveal answer
beginner
What does '-z' check in bash string tests?
The '-z' operator checks if a string is empty (zero length). It returns true if the string has no characters.
Click to reveal answer
beginner
What does '-n' check in bash string tests?
The '-n' operator checks if a string is not empty. It returns true if the string has one or more characters.
Click to reveal answer
beginner
Write a simple bash if statement to check if variable 'name' is empty.
if [ -z "$name" ]; then
echo "Name is empty"
fi
This uses '-z' to test if 'name' has zero length.
Click to reveal answer
Which operator checks if two strings are equal in bash?
✗ Incorrect
The '=' operator tests if two strings are exactly equal.
What does the '-z' operator test for in bash?
✗ Incorrect
The '-z' operator returns true if the string length is zero (empty).
How do you test if two strings are NOT equal in bash?
✗ Incorrect
The '!=' operator returns true if the strings differ.
Which operator returns true if a string is NOT empty?
✗ Incorrect
The '-n' operator checks if a string has one or more characters.
What will this bash test return? [ -z "hello" ]
✗ Incorrect
Since 'hello' is not empty, '-z' returns false.
Explain how to check if a string variable is empty or not in bash using string comparison operators.
Think about testing zero length strings.
You got /4 concepts.
Describe the difference between '=' and '!=' operators in bash string comparisons.
One checks if strings match, the other if they differ.
You got /4 concepts.