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?" ;;
esacResult
Pass match tmp exists hi Ada
Exercise
Close an if block.
if true; then echo a; Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.