# cal command

**URL:** <https://community.unix.com/t/cal-command/268552>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [June 29, 2010, 10:10am UTC](https://community.unix.com/t/cal-command/268552 "2010-06-29T10:10:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![atlantis](https://community.unix.com/letter_avatar/atlantis/32/5_5575768a8748004e209b776fc1b2916d.png) [@atlantis](https://community.unix.com/u/atlantis)\
**Post date:** [June 29, 2010, 10:10am UTC](https://community.unix.com/t/cal-command/268552/1 "2010-06-29T10:10:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/5_5575768a8748004e209b776fc1b2916d.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [June 29, 2010, 10:29am UTC](https://community.unix.com/t/cal-command/268552/2 "2010-06-29T10:29:49Z")

</div>

"cal -3" is a syntax error.

This script should do it.

```nohighlight
#!/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

```

---

<div class="post-metadata">

**Author:** ![atlantis](https://community.unix.com/letter_avatar/atlantis/32/5_5575768a8748004e209b776fc1b2916d.png) [@atlantis](https://community.unix.com/u/atlantis)\
**Post date:** [June 29, 2010, 10:33am UTC](https://community.unix.com/t/cal-command/268552/3 "2010-06-29T10:33:34Z")

</div>

Hi,

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

Thanks.

---

<div class="post-metadata">

**Author:** ![anbu23](https://community.unix.com/user_avatar/community.unix.com/anbu23/32/351_2.png) [@anbu23](https://community.unix.com/u/anbu23)\
**Post date:** [June 29, 2010, 10:40am UTC](https://community.unix.com/t/cal-command/268552/4 "2010-06-29T10:40:10Z")

</div>

> [@atlantis](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![atlantis](https://community.unix.com/letter_avatar/atlantis/32/5_5575768a8748004e209b776fc1b2916d.png) [@atlantis](https://community.unix.com/u/atlantis)\
**Post date:** [June 29, 2010, 10:43am UTC](https://community.unix.com/t/cal-command/268552/5 "2010-06-29T10:43:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![verdepollo](https://community.unix.com/user_avatar/community.unix.com/verdepollo/32/1854_2.png) [@verdepollo](https://community.unix.com/u/verdepollo)\
**Post date:** [June 29, 2010, 10:48am UTC](https://community.unix.com/t/cal-command/268552/6 "2010-06-29T10:48:56Z")

</div>

> [@anbu23](#):
>
> Can you tell us in which OS you were able to run cal -3?

cal from util-linux-ng and util-linux. 😃

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/5_5575768a8748004e209b776fc1b2916d.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [June 29, 2010, 11:02am UTC](https://community.unix.com/t/cal-command/268552/7 "2010-06-29T11:02:08Z")

</div>

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