Einstein47
Programmer
Hey all,
I have a script that generates a report based on the month that a user enters. Is there a better way to do this than I have here? I'm sure there must be something more simple, and I am always wanting to learn.
Which at the end I have two variables: month and year. This code is really ugly and if someone has something more direct or simple, I'd be willing to learn (and give stars).
Thanks, Einstein47
("For every expert, there is an equal and opposite expert." - Arthur C. Clarke)
I have a script that generates a report based on the month that a user enters. Is there a better way to do this than I have here? I'm sure there must be something more simple, and I am always wanting to learn.
Code:
#!/bin/ksh
ACTION=$(expr ${1} )
if [ -z "$ACTION" ];then
echo "Enter month to report (enter for current) : \c"
read tmp
else
tmp=`echo " " | awk -v MONTH=$ACTION '{ if ( index( "123456789101112", MONTH ) != 0 ) { print MONTH } }'`
fi
year=$(date +%Y)
tmonth=$(date +%m)
if [ "$tmp" = "" ];then
month=$tmonth
else
month=$(echo "0$tmp"|awk '{ print substr($1,length($1)-1) }' )
if [ $month -gt $tmonth ];then
(( year = year - 1 ))
fi
fi
Thanks, Einstein47
("For every expert, there is an equal and opposite expert." - Arthur C. Clarke)