Re: case statement question...
David Oswald <david.oswald@citicorp.com> writes:
>
> Hello all - I have a KSH script question...
>
> Can someone out there take a look at this script. I want to perform an
> operation based on the day of month. but the days (10 - 31) are giving
> me a problem. I would really like to keep this a one liner if i can. How
> bout anybody out there done something like this ???
>
> Only the line [30-31] is the offending line...
>
>
> #!/bin/ksh
> echo "Enter the date: (ie Nov 04)"
> read Month Day
> case $Day in
> 1 | 01 ) Day=01; SearchStr="$Month 1";;
> 2 | 02 ) Day=02; SearchStr="$Month 2";;
> 3 | 03 ) Day=03; SearchStr="$Month 3";;
> 4 | 04 ) Day=04; SearchStr="$Month 4";;
> 5 | 05 ) Day=05; SearchStr="$Month 5";;
> 6 | 06 ) Day=06; SearchStr="$Month 6";;
> 7 | 07 ) Day=07; SearchStr="$Month 7";;
> 8 | 08 ) Day=08; SearchStr="$Month 8";;
> 9 | 09 ) Day=09; SearchStr="$Month 9";;
Looking at the above lines, I am thinking that you probably don't want
the semicolons after the Day= instructions.
A simpler way would be something like:
[1-9]) Day="0$Day" SearchStr="$Month $Day";;
0[1-9]) SearchStr="$Month `echo $Day | sed 's/^0//'`"
> [30-31]) SearchStr="$Month $Day";;
If you want to match all the dates 10-31 here, you want the expression
`[12][0-9] | 3[0-1])' instead.
> *) ERROR;; # call error routine
> esac
>
> echo $SearchStr
All of this is untested so it should be taken with quite a tonnage of
salt.
--
Ben Pfaff <pfaffben@pilot.msu.edu> <blp@gnu.org> <pfaffben@debian.org>
Senders of unsolicited commercial e-mail will receive free 32MB core files!
--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org .
Trouble? e-mail to templin@bucknell.edu .
Reply to: