Openunix.eu
IF, ELSE, ELIF, CASE
- IF basic
if [ $x -eq 7 ] ; then
echo " It is 7. "
fi
- IF + else
if [ $x -eq 7 ] ; then
echo " It is 7. "
else
echo "It is not 7."
fi
- IF + elif
if [ $x -eq 7 ] ; then
echo " It is 7. "
elif [ $x -gt 7 ] ; then
echo " It is more then 7. "
elif [ $x -lt 7 ] ; then
echo " It is less then 7. "
fi
- IF + negative condition
if ! [ $x -eq 7 ] ; then
echo " It is not 7. "
fi
- CASE (if with predefined options)
case $answer in "100M" "150M" "200M"
100M ) echo " Not much space. " ;;
150M ) ehco " Medium? O.K. ";;
200M ) echo " Plenty of space! " ;;
esac
Powered by NetBSD. Running on a toaster.