LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   customize cal command (https://www.linuxquestions.org/questions/linux-newbie-8/customize-cal-command-930458/)

kakalig2007 02-21-2012 04:06 AM

customize cal command
 
I want to customize cal command so that it accepts more than one month, like $./cal.sh cal 1 3.[January,March]
I have done this for two months,but cannot generalize for more than two months, e.g. cal 1 3 4 or any number of arguments not decided beforehand.
My code:
#!/bin/bash
if [ $# -gt 1 ];then
t=$( 'date' '+20%y' )
if [ $2 -ge 1 -a $2 -le 12 -a $3 -ge 1 -a $3 -le 12 ]
then
cal $2 $t; cal $3 $t
fi
fi
Thanks in advance....

catkin 02-21-2012 04:26 AM

Something like
Code:

#!/bin/bash
year=$( 'date' '+20%y' )
while [[ $# -gt 0 ]]
do
    if [[ ! $1 =~ ^[0-9]+$ ]]; then
        echo "'$1' is not an unsigned integer; ignoring it"
        continue
    fi
    if (( $1 < 1 || $1 > 12 )); then
        echo "'$1' is not a valid month number; ignoring it"
        continue
    fi
    cal $1 $year
    shift
done



All times are GMT -5. The time now is 10:26 AM.