Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Wednesday, 22 February 2012

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.


HH=`date +%H`
time=`date +"%S %p"`
if [ $HH -ge 12 ];then
HH=`expr $HH % 12`
if [ $HH -lt 5 ];then
msg="GOOD AFTERNOON"
elif [ $HH -ge 5 ]  &&  [ $HH -lt 9 ];then
msg="GOOD EVENING"
else
msg="GOOD NIGHT"
fi
echo "$msg ,CURRENT TIME $HH:$time"
exit 1
else
if [ $HH -lt 5 ];then
msg="GOOD NIGHT"
else
msg="GOOD MORNING"
fi
echo "$msg ,CURRENT TIME $HH:$time"
exit 1
fi

No comments:

Post a Comment