Recall & Review
beginner
What does the '-a' operator do in bash scripting?
The '-a' operator means AND. It checks if both conditions on its sides are true.
Click to reveal answer
beginner
What is the purpose of the '-o' operator in bash?
The '-o' operator means OR. It checks if at least one of the conditions is true.
Click to reveal answer
beginner
What does the '!' operator do in bash conditional expressions?
The '!' operator means NOT. It reverses the result of the condition that follows it.
Click to reveal answer
intermediate
How would you write a condition to check if a file exists AND is readable using '-a'?
You write: [ -e filename -a -r filename ] which means the file exists AND is readable.
Click to reveal answer
intermediate
Why should you be careful when mixing '-a' and '-o' in the same test expression?
Because '-a' and '-o' have different precedence and can cause unexpected results. It's safer to use separate tests or parentheses.
Click to reveal answer
In bash, what does '[ -f file -a -w file ]' check?
✗ Incorrect
The '-a' means AND, so both conditions must be true: file exists (-f) AND file is writable (-w).
What does the '!' operator do in '[ ! -e folder ]'?
✗ Incorrect
'!' negates the condition, so it checks if the folder does NOT exist.
Which operator means OR in bash test expressions?
✗ Incorrect
'-o' means OR, checking if either condition is true.
Why might mixing '-a' and '-o' in one test be risky?
✗ Incorrect
Different precedence can cause unexpected results, so it's better to separate conditions.
How do you write a condition to check if a file is NOT empty using '!'?
✗ Incorrect
'-s' checks if file size is greater than zero; '!' negates it, so '[ ! -s file ]' means file is empty.
Explain how to use '-a', '-o', and '!' in bash conditional tests with simple examples.
Think about checking file properties with AND, OR, and negation.
You got /5 concepts.
Describe a real-life scenario where you might use logical operators '-a', '-o', and '!' in a bash script.
Imagine checking if a file is ready to be processed.
You got /5 concepts.