Bird
0
0

How would you fix this script to correctly print "Allowed" only if age is NOT less than 18?

hard🚀 Application Q9 of 15
Bash Scripting - Conditionals
How would you fix this script to correctly print "Allowed" only if age is NOT less than 18?
age=16
if [ $age -lt 18 ]; then
  echo "Allowed"
fi
AChange -lt to -ge in the if condition
BAdd else branch with echo "Allowed"
CUse -ne 18 instead of -lt 18
DNo fix needed, script is correct
Step-by-Step Solution
Solution:
  1. Step 1: Understand current condition meaning

    Current condition checks if age is less than 18, then prints "Allowed" which is opposite of requirement.
  2. Step 2: Fix condition to check age NOT less than 18

    Use -ge (greater or equal) 18 to print "Allowed" only if age is 18 or more.
  3. Final Answer:

    Change -lt to -ge in the if condition -> Option A
  4. Quick Check:

    Use -ge to check NOT less than 18 [OK]
Quick Trick: Use -ge to check greater or equal, not -lt [OK]
Common Mistakes:
MISTAKES
  • Confusing condition logic
  • Adding else instead of fixing condition
  • Using -ne incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes