Script 34
Script 34
Definition:
Write a shell script to display the calendar in the following manner:
i. Display the calendar of months m1 and m2 by ‘CAL m1, m2’ commandfile.
ii. Display the calendar of the months from m1 to m2 by ‘CAL m1-m2’ commandfile.
Script:
clear
echo M E N U
echo 1: Display the calendar of months m1 and m2
echo 2: Display the calendar of the months from month m1 to m2
echo Enter your choice
read ch
case $ch in
1) cal $1 `date "+%Y"` |more ;cal $2 `date "+%Y"` |more ;;
2) i=$1
while [ $i -le $2 ]
do
clear
cal $i `date "+%Y"` |more
sleep 2
i=`expr $i + 1`
done;;
*) echo Invalid choice;;
esac
OR
if [ $# -eq 2 ]
then
y="-"
z=","
l=`echo $1 | wc -c`
i=1
c=0
while [ $i -le $l ]
do
x=`echo $1 | cut -c $i`
if [ $x=$y ]
then
c=1
break
elif [ $x=$z ]
c=2
break
fi
i=`expr $i+1`
done
if [ $c -eq 1 ]
then
first=`echo $1 | cut -d "-" -f1`
second=`echo $1 |cut -d "-" -f2`
while [ $first -le $second ]
do
cal $first 24
first=`expr $first +1`
done
elif [ $c -eq 2 ]
then
first=`echo $1 | cut -d "," -f1`
second=`echo $1 | cut -d "," -f2`
cal $first 24
cal $second 24
else
echo "Argument not entered correctly"
fi
else
echo "Invalid arguments"
fi