Tsallaka zuwa abun ciki
Justice Tech School

Conditions

if uses [[ ]] for tests. Numbers compare with -eq -gt -lt, strings with == and !=. File tests include -f (file exists) and -d (directory). && and || chain commands.

Example
score=72
if [[ $score -ge 70 ]]; then
  echo "Pass"
else
  echo "Retake"
fi
name="ada"
[[ $name == "ada" ]] && echo "match"
[[ -d /tmp ]] && echo "tmp exists"
case "$name" in
  ada) echo "hi Ada" ;;
  *) echo "who?" ;;
esac

Result

Pass
match
tmp exists
hi Ada

Exercise

Close an if block.

if true; then echo a; 

Quiz Test

Which operator tests numbers greater than?

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