The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
A challenging problem involving symbolic links. ibloom High Level Programming 2 03-24-2008 10:07 AM
(+ sign) Unexpected arithmetic expr script interpretation Birdi6022 UNIX for Dummies Questions & Answers 9 08-11-2007 10:28 AM
problem in arithmetic operations ithirak17 Shell Programming and Scripting 3 02-06-2007 06:46 AM
arithmetic problem inquirer UNIX for Dummies Questions & Answers 2 02-20-2002 02:27 AM
Unix + oracle doubt....involving shell script mexx_freedom UNIX for Dummies Questions & Answers 2 08-02-2001 09:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-30-2007
rajarp rajarp is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 3
problem in script involving month arithmetic

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 ,inc_flg should be set to '1' otherwise inc_flg should be set to '2'


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 i am getting inc_flg =2 always.please help me to solve this issue.Is there anyother way to write a script???please help me.thanks in advance
regards,
rajarp
  #2 (permalink)  
Old 12-30-2007
VISH VISH is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 2
Thumbs up

u can directly subtituite command in loop u can do this it works

#!/bin/sh

if [ `date +"%m"` -eq 3 ] | [ `date +"%m"` -eq 6 ] | [ `date +"%m"` -eq 9 ] | [ `date +"%m"` -eq 12 ] ; then
echo "inc_flg = 1"
else
echo "inc_flg = 2"
fi
  #3 (permalink)  
Old 12-30-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
Quote:
Originally Posted by rajarp View Post
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
You are missing the backticks.
  #4 (permalink)  
Old 12-30-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
Quote:
Originally Posted by rajarp View Post
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 ,inc_flg should be set to '1' otherwise inc_flg should be set to '2'


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 i am getting inc_flg =2 always.please help me to solve this issue.Is there anyother way to write a script???please help me.thanks in advance
regards,
rajarp
"neater" way to write your if else statement
Code:
...
 case $month in 
   3|6|9|12)  echo "yes";; 
    *) echo "no";; 
 esac
..
  #5 (permalink)  
Old 12-31-2007
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,913
Code:
typeset -i 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
  #6 (permalink)  
Old 12-31-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
3,6,9,12 all have a remainder of zero when divided by 3. The other months will have a non-zero remainder. You can use month%3 as the test. If you must have variable called inc_flg with the above mentioned properties, you could just do:
((inc_flg=2-!(month%3)))
  #7 (permalink)  
Old 01-02-2008
rajarp rajarp is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 3
u have made my day gud gentlemen..i have used reborg's stuff.....But thanks for all.........
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0