| | |
issue in a script invloving month arithmetic
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2007
Posts: 4
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
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:
Hope that helped you out 
, Mike
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)
month=`date +"%m"` if [ "$month" -eq 3 -o "$month" -eq 6 -o "$month" -eq 9 -o "$month" -eq 12 ] then inc_flg=1 else inc_flg=2 fi echo "INC_FLG $inc_flg"

, 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!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
![]() |
Other Threads in the Shell Scripting Forum
- Previous Thread: Help! i need to edit .* files in a particular directory
- Next Thread: Wat is shell?
| Thread Tools | Search this Thread |





