0% found this document useful (0 votes)
15 views3 pages

Script 34

The document outlines a shell script that displays calendars for specified months. It provides a menu for users to choose between displaying calendars for two specific months or for a range of months. The script handles user input and validates the arguments to ensure correct execution.

Uploaded by

for11trade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Script 34

The document outlines a shell script that displays calendars for specified months. It provides a menu for users to choose between displaying calendars for two specific months or for a range of months. The script handles user input and validates the arguments to ensure correct execution.

Uploaded by

for11trade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Script No .

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

You might also like