LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   small script (http://www.linuxquestions.org/questions/programming-9/small-script-5877/)

msj 08-26-2001 11:25 AM

small script
 
I am trying to write a small script that would
first say hi from 6am to 12 pm and say Good afternood from
1pm to 5pm. I know we use if but it seems I'm doing something wrong.

if $date "+%T" -ge 6 -a le 12
then
echo "Good morning"
fi

if $date "+%T" -ge 1 -a le 5
then
echo "Good afternoon"
fi

Please tell me what's wrong in there, I can't find it.

Thanks:newbie:

acid_kewpie 08-26-2001 12:42 PM

You're not using 'test' to actually evaulate your code. the conditoin checking should be encased in square brackets [ ] OR be chaged to `test .... ` Remember that shell programming is not one large programming langauge, but a collection of individual programs which rely on useful outputs from others...

try this...

-------------
HOUR=`date '+%H'`

if [ $HOUR -ge 18 ]
then
echo Good Evening
exit
fi

if [ $HOUR -ge 12 ]
then
echo Good Afternoon
exit
fi

if [ $HOUR -ge 6 ]
then
echo Good Morning
exit
fi

echo Criminy!! What are you doing up at this time?!!
--------

Any Help? I'm not very good at shell script, but i had nothign else to do at work.... ;-)


All times are GMT -5. The time now is 08:37 PM.