LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-21-2012, 05:06 AM   #1
kakalig2007
LQ Newbie
 
Registered: Jul 2008
Posts: 11

Rep: Reputation: 0
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....
 
Old 02-21-2012, 05:26 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hello to all from new guy in So. Cal. rgm1960 LinuxQuestions.org Member Intro 2 05-24-2010 04:42 PM
Use Cal instead of date command - Bash Blackout_08 Programming 1 06-22-2006 12:39 PM
Cal command Blackout_08 Programming 9 06-08-2006 06:56 PM
"cal" command question tanawana Debian 2 10-13-2005 05:25 AM
unix cal command in an odd situation GUIPenguin General 5 10-12-2005 05:10 PM


All times are GMT -5. The time now is 03:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration