Challenge - 5 Problems
Logical Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:00remaining
What is the output of this Bash test command?
Consider the following Bash command:
What will be printed when this command runs?
if [ 5 -gt 3 -a 2 -lt 4 ]; then echo "True"; else echo "False"; fi
What will be printed when this command runs?
Bash Scripting
if [ 5 -gt 3 -a 2 -lt 4 ]; then echo "True"; else echo "False"; fi
Attempts:
2 left
💡 Hint
Remember that '-a' means AND in Bash test expressions.
✗ Incorrect
The condition checks if 5 is greater than 3 AND 2 is less than 4. Both are true, so the whole condition is true, printing 'True'.
💻 Command Output
intermediate1:00remaining
What does this Bash condition print?
Look at this Bash snippet:
What will be the output?
if [ ! 0 -eq 1 ]; then echo "Yes"; else echo "No"; fi
What will be the output?
Bash Scripting
if [ ! 0 -eq 1 ]; then echo "Yes"; else echo "No"; fi
Attempts:
2 left
💡 Hint
The '!' operator negates the condition that follows it.
✗ Incorrect
0 equals 1 is false, negating it with '!' makes the condition true, so it prints 'Yes'.
💻 Command Output
advanced1:30remaining
What is the output of this complex Bash test?
Analyze this Bash command:
What will it print?
if [ 3 -lt 2 -o \( 4 -eq 4 -a ! 5 -gt 10 \) ]; then echo "Pass"; else echo "Fail"; fi
What will it print?
Bash Scripting
if [ 3 -lt 2 -o \( 4 -eq 4 -a ! 5 -gt 10 \) ]; then echo "Pass"; else echo "Fail"; fi
Attempts:
2 left
💡 Hint
Remember '-o' means OR, '-a' means AND, and '!' negates the condition. Parentheses group conditions.
✗ Incorrect
3 < 2 is false, but the grouped condition (4 == 4 AND NOT 5 > 10) is true, so overall condition is true, printing 'Pass'.
💻 Command Output
advanced1:00remaining
What error does this Bash test command raise?
What happens when you run this command?
if [ 5 -gt 3 -a ! ]; then echo "OK"; else echo "Not OK"; fi
Bash Scripting
if [ 5 -gt 3 -a ! ]; then echo "OK"; else echo "Not OK"; fi
Attempts:
2 left
💡 Hint
The '!' operator must be followed by a condition.
✗ Incorrect
The '!' operator is used without a condition, causing a syntax error in the test expression.
💻 Command Output
expert2:00remaining
What is the value of variable RESULT after running this script?
Given this Bash script:
What will be printed?
RESULT=0 if [ ! \( 2 -eq 2 -o 3 -lt 1 \) ]; then RESULT=1; else RESULT=2; fi echo $RESULT
What will be printed?
Bash Scripting
RESULT=0 if [ ! \( 2 -eq 2 -o 3 -lt 1 \) ]; then RESULT=1; else RESULT=2; fi echo $RESULT
Attempts:
2 left
💡 Hint
Evaluate inside the parentheses first, then apply the negation.
✗ Incorrect
Inside parentheses: 2 == 2 is true, 3 < 1 is false, so OR is true. Negating true gives false, so else branch runs, RESULT=2.