The UNIX Forums
"Join the Network of UNIX System Users"


 
hans
Newbie
Rank: 1



UID 171
Digest Posts 0
Credits 0
Posts 43
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:36 AM  Profile | P.M. 
case structure



case structure



hi,

can anyone help me with the following case structure?


code:
echo "please enter the date for which you want the report:\c"
read dat
d1=`echo $dat|cut -c7-8`
m1=`echo $dat|cut -c5-6`
y1=`echo $dat|cut -c1-4`

yr=`expr "$d1" - 1`
case "$yr" in
        0)
           month=`expr "$m1" - 1`
           year=y1
           ;;
                case "$m1" in
                        0)

                           month=12
                           year=`expr "$y1" - 1`
                        ;;
                esac
        day=`cal $month $year |grep . | fmt -1 | tail -1`
esac

it returns me an error:

`"$m1"' is not expected

thanks for your help


Top
DMK
Newbie
Rank: 1



UID 118
Digest Posts 0
Credits 0
Posts 41
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:37 AM  Profile | P.M. 
a small mistake and it made all the difference.


code:
echo "please enter the date for which you want the report:\c"
read dat
d1=`echo $dat|cut -c7-8`
m1=`echo $dat|cut -c5-6`
y1=`echo $dat|cut -c1-4`

yr=`expr "$d1" - 1`
case "$yr" in
        0)
           month=`expr "$m1" - 1`
           year=$y1
#           ;;  - this was not required
                case "$m1" in
                        0)
                           month=12
                           year=`expr "$y1" - 1`
                        ;;
                esac
        day=`cal $month $year |grep . | fmt -1 | tail -1`
Top
 

 

All times are GMT, the time now is Mar 22, 2010 01:55 PM

Powered by Discuz! 5.0.0  © 2001-2006 UNIX Forums
Processed in 0.004799 second(s), 8 queries

Clear Cookies - Contact Us - UNIX Help - Archiver - WAP