Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't figure out error...

Status
Not open for further replies.

rkm2w

MIS
Sep 12, 2002
2
US
Can anyone help with this simple script? It is right out a Unix manual I have. I get the error below:

hour=`date | cut -c12-13`
case $hour in
[$hour -lt 12] ) echo "Good Morning" ;;
[$hour -lt 18] ) echo "Good Afternoon" ;;
*) echo "Good Evening" ;;
esac
exit 0
ERROR
./greetings: line 3: syntax error near unexpected token `$hour'
./greetings: line 3: ` [ $hour -lt 12 ] ) echo "Good Morning" ;;'
 
You're mixing up the comparison and case statements
Try :

hour=`date | cut -c12-13`
case $hour in
1|2|3|4|5|6|7|8|9|10|11|12) echo "Good Morning" ;;
13|14|15|16|17 ) echo "Good Afternoon" ;;
*) echo "Good Evening" ;;
esac
exit 0

HTH;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
The book originally had:
0? 1[0-1] ) echo "Good Morning";;
1[2-7] )....
*)...

This didn't work either.

I was able to get yours to work, but I had to add a 0 in front of all the single hour numbers - 02 instead of 2.

Thanks for your help!
 
#!/bin/ksh

hour=`date | cut -c12-13`
echo "hour->[${hour}]"
#hour="11"
echo "hour->[${hour}]"
case ${hour} in
@(0[0-9]|1[1-2]) ) echo "Good Morning" ;;
@(1[3-7]) ) echo "Good Afternoon" ;;
*) echo "Good Evening" ;;
esac
exit 0
vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top