0
0
Bash Scriptingscripting~20 mins

Why conditionals branch script logic in Bash Scripting - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Conditional Logic Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Bash script with conditionals?
Consider the following Bash script. What will it print when run?
Bash Scripting
count=5
if [ $count -gt 3 ]; then
  echo "Count is greater than 3"
else
  echo "Count is 3 or less"
fi
ASyntax error
BCount is 3 or less
CCount is greater than 3
DNo output
Attempts:
2 left
💡 Hint
Check the condition if count is greater than 3.
💻 Command Output
intermediate
2:00remaining
What output does this nested conditional produce?
What will this Bash script print?
Bash Scripting
value=10
if [ $value -lt 5 ]; then
  echo "Less than 5"
elif [ $value -eq 10 ]; then
  echo "Equal to 10"
else
  echo "Other value"
fi
AEqual to 10
BLess than 5
COther value
DSyntax error
Attempts:
2 left
💡 Hint
Check the elif condition carefully.
🔧 Debug
advanced
2:00remaining
Why does this Bash script fail to run?
This script is intended to print "Positive" if the number is greater than zero, but it fails. What is the error?
Bash Scripting
num=3
if [ $num -gt 0 ]; then
  echo "Positive"
fi
ANo output because condition is false
BRuns correctly and prints "Positive"
CRuntime error: variable not defined
DSyntax error due to incorrect comparison operator
Attempts:
2 left
💡 Hint
Check the operator used inside the square brackets.
💻 Command Output
advanced
2:00remaining
What does this script print with multiple conditions?
What is the output of this Bash script?
Bash Scripting
score=75
if [ $score -ge 90 ]; then
  echo "Grade A"
elif [ $score -ge 80 ]; then
  echo "Grade B"
elif [ $score -ge 70 ]; then
  echo "Grade C"
else
  echo "Grade F"
fi
AGrade C
BGrade A
CGrade B
DGrade F
Attempts:
2 left
💡 Hint
Check which condition matches the score first.
💻 Command Output
expert
2:00remaining
What is the output of this Bash script using logical AND in condition?
What will this script print?
Bash Scripting
a=5
b=10
if [ $a -lt 10 ] && [ $b -gt 5 ]; then
  echo "Both conditions true"
else
  echo "One or both conditions false"
fi
AOne or both conditions false
BBoth conditions true
CSyntax error due to missing semicolon
DNo output
Attempts:
2 left
💡 Hint
Both conditions must be true for the if to run.