issue in a script invloving month arithmetic

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2007
Posts: 4
Reputation: rajarp is an unknown quantity at this point 
Solved Threads: 0
rajarp rajarp is offline Offline
Newbie Poster

issue in a script invloving month arithmetic

 
0
  #1
Dec 30th, 2007
advance happy new year to all,
i am having a script.The purpose of the scripts is as follows.If the current month is march,june,september or december ,increment flag should be set to '1' otherwise increment flag should be set to '2'.the script is as follows


month= date +"%m"
if [ "$month" -eq 3 ] || [ "$month" -eq 6 ] || [ "$month" -eq 9 ] ||
[ "$month" -eq 12 ] ; then
inc_flg = 1
else
inc_flg = 2
fi

But am getting inc_flg =2 always.please help me to solve this issue.Is there anyother way to write a script???please help me.
regards,
rajarp
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: issue in a script invloving month arithmetic

 
0
  #2
Dec 31st, 2007
Hey There,

I'm not sure what you're looking to do over time (since you'll have to deal with leap years, etc), but the two things I found in the script were the way the "if" statement was setup and the assignment for the "month" variable.

I rewrote it very quickly like this and it gives you the result you wanted:

Shell Scripting Syntax (Toggle Plain Text)
  1. month=`date +"%m"`
  2. if [ "$month" -eq 3 -o "$month" -eq 6 -o "$month" -eq 9 -o "$month" -eq 12 ]
  3. then
  4. inc_flg=1
  5. else
  6. inc_flg=2
  7. fi
  8. echo "INC_FLG $inc_flg"
Hope that helped you out

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 4
Reputation: rajarp is an unknown quantity at this point 
Solved Threads: 0
rajarp rajarp is offline Offline
Newbie Poster

Re: issue in a script invloving month arithmetic

 
0
  #3
Jan 2nd, 2008
Really thanks for ur suggestions eggi....
Last edited by rajarp; Jan 2nd, 2008 at 12:21 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC