Skip to content
Justice Tech School

if, elif and else

Run commands by condition. [[ ]] is the Bash test. Combine with && and ||.

Example
n=15
if (( n % 15 == 0 )); then echo FizzBuzz
elif (( n % 3 == 0 )); then echo Fizz
else echo "$n"
fi
[[ $n -gt 10 && $n -lt 20 ]] && echo "in range"

Result

FizzBuzz
in range

Exercise

End an if.

if true; then echo; 

Quiz Test

How does an if end?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.