postheadericon date command in unix


#Write a script to display the date, time and a welcome message (like Good Morning etc.). The time should be displayed with “a.m.” or “p.m.” and not in 24 hours notation.

currentHour=`date +%H`

currentTime=`date +"%I : %M : %S %p"`

if [ $currentHour -lt 12 ]
then
    msg="Good Morning"

elif [ $currentHour -ge 12 ]  &&  [ $currentHour -lt 16 ]
then
    msg="Good Afternoon"

elif [ $currentHour -ge 16 ]  &&  [ $currentHour -lt 21 ]
then
    msg="Good Evening"
else
    msg="Good Night"
fi
#format of time  [ HH : MM : SS : AM/PM]
echo "$msg ,\nCurrent Time is  $currentTime"

0 comments:

Follow by Email

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.