shell script program to greet based on system time in linux

Shell program to greet user based on system time in the operating system suppose time in operating system is 8:00 am then it will display “good morning”. if it is noon then it wi display the “Good afternoon “

shell script program to greet based on system time in linux

To do this date command is used to display the time and check the current time in operating system and check the condition based of time to decide the result.

t=””

ct=`echo $(date +”%H:%M:%S”)`

t=`echo $(date +”%H”)`

echo $ct

if [ $t -le 10 -a $t -ge  6 ]

then

echo ” Good morning “

elif [ $t -gt 10 -a $t -le 16 ]

then

echo ” good after noon”

elif [ $t -gt 16 -a $t -le 20 ]

then

echo “good evening “

elif [ $t -gt 20 -a $t -le 5 ]

then

echo ” good night “

fi

Output:

Leave a comment