cal command

Hello,

I wanted to display calender for the previou, current and next month in a single command...

I used the command cal -3 for this. But its throwing me a Bad Argument error.

I am using HP UX to execute this command. Is this a syntax error, or let me know if there any other ways to display the 3 months.

Thanks.

"cal -3" is a syntax error.

This script should do it.

#!/bin/ksh
YYYY1=`date +%Y`
YYYY2=${YYYY1}  # Initial value - may change
YYYY3=${YYYY1}  # Initial value - may change
MM1=`date +%m`
MM2=`expr ${MM1} - 1`
MM3=`expr ${MM1} + 1`
if [ "${MM2}" -lt 1 ]
then
        MM2=12
        YYYY2=`expr ${YYYY2} - 1`
fi
if [ "${MM3}" -gt 12 ]
then
        MM3=1
        YYYY3=`expr ${YYYY3} + 1`
fi
cal ${MM2} ${YYYY2}     # Last month
cal ${MM1} ${YYYY1}     # This month
cal ${MM3} ${YYYY3}     # Next month

Hi,

Thanks for the quick reply with the script. But I was asked to do that in a single command.

Thanks.

Can you tell us in which OS you were able to run cal -3?

Hello,
I got this command cal -3, when doing google on the same.

NAME

cal - displays a calendar
SYNOPSIS

cal [-smjy13 ] [[ month ] year ]
DESCRIPTION

Cal displays a simple calendar. If arguments are not specified, the current month is displayed. The options are as follows:

-1 Display single month output. (This is the default.) -3 Display prev/current/next month output. -s Display Sunday as the first day of the week. (This is the default.) -m Display Monday as the first day of the week. -j Display Julian dates (days one-based, numbered from January 1). -y Display a calendar for the current year.

cal from util-linux-ng and util-linux. :smiley:

HP-UX does not have those Linux extensions to "cal".