Introduction
Use if-elif-else to make decisions in your script based on different conditions.
if [ condition ]; then # commands if condition is true elif [ another_condition ]; then # commands if another_condition is true else # commands if none of the above conditions are true fi
if [ "$age" -ge 18 ]; then echo "You are an adult." else echo "You are a minor." fi
if [ "$color" = "red" ]; then echo "Stop" elif [ "$color" = "yellow" ]; then echo "Caution" else echo "Go" fi
#!/bin/bash read -p "Enter a number: " num if [ "$num" -gt 0 ]; then echo "The number is positive." elif [ "$num" -lt 0 ]; then echo "The number is negative." else echo "The number is zero." fi
if-elif-else structure do in a Bash script?#!/bin/bash num=7 if [ $num -lt 5 ]; then echo "Less than 5" elif [ $num -eq 7 ]; then echo "Equal to 7" else echo "Other" fi
if [ $value -gt 10 ] echo "Greater than 10" elif [ $value -eq 10 ]; then echo "Equal to 10" else echo "Less than 10" fi
num. Which script correctly uses if-elif-else to do this?Pass the test and this pattern moves unknown