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

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by rajarp
0

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:

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"

Hope that helped you out :)

, Mike

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.