Simple if:
if [ -d /etc]; then
echo "/etc exists"
fi
if with else
if [ -f /etc/fstab ]; then
echo "/etc/fstab exists"
else
echo "/etc/fstab does not exists"
fi
if with else - example 2
count=100
if [ $count -eq 100 ]
then
echo Count is 100
else
echo Count is not 100
fi
if with else example 3 here - check if file exists:
if [ -e /etc/os-release ]
then
echo "File exists"
else
echo "File doesn't exist"
fi
if statement - check if a variable value is met
a=`date | awk '{ print $1 }'`
if [ "$a" == Mon ]
then
echo Today is $a
else
echo Today is not Monday
fi
if with elif and else
if [ $1 = "y" ]; then
echo "yes"
elif [ $1 = "n" ]; then
echo "no"
else
echo "other"
fi
if with elif and else example 2 - check the responce and output
clear
echo "What is yout name?"
echo
read name
echo
echo Hello $name
echo
echo "Do you like working in IT? (y/n)"
echo
read like
echo
if [ "$like" == y ]
then
echo You are cool
elif [ "$like" == n ]
then
echo "You should try IT, it is a good field"
echo
fi
if with test
if test -e /etc/hosts; then
echo "/etc/hosts exists"
fi
if with || and [[ ]]if [[ -f /etc/fstab || -d /var2 ]]; then
echo "true"
else
echo "false"
fi
if with && and [ ]
[ ] - a single expression
if [ -f /etc/fstab ] && [ -d /var2 ]; then
echo "true"
else
echo "false"
fi