Articles: BASH IF ELSE Example Plus Nested IF Example

Posted by: david on 09/25/2010 - 06:20 PM
Here is an example of the usage of an IF Else with a Nested IF for writing a script for BASH:

current_hour=$(date +"%H");

#if it is past midnight but not yet 6 AM
if [ $current_hour -ge 0 -a $current_hour -lt 6 ]
then
    echo "You are not in bed yet?"
else
    #if it is 6PM but not yet 8PM
    if [ $current_hour -ge 18 -a $current_hour -lt 20 ]
    then
         echo "Dinner time!"
     fi
fi

Here are some BASH if/then logic syntax in-depth examples and tutorial via video: