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

Recommended Answers

All 2 Replies

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

Really thanks for ur suggestions eggi....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.