The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
If statement - How to write a null statement april Shell Programming and Scripting 3 04-16-2008 10:14 AM
Using write() with integers in C h@run High Level Programming 2 02-11-2008 11:46 AM
Add non-integers using ksh 2dumb Shell Programming and Scripting 17 04-30-2007 10:55 AM
how do you represent non integers in a shell script? TRUEST UNIX for Dummies Questions & Answers 2 05-17-2003 10:00 PM
Check if argument passed is an integers elchalateco Shell Programming and Scripting 13 11-07-2002 06:23 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-22-2008
Registered User
 

Join Date: May 2007
Posts: 27
integers in the if statement

hi, im trying to compare two variables in csh to put in an if statement, eg:

set a = $firstnum
set b = $secondnum
if ($a -ge $b) echo $a

But I get an error ("if: Expression syntax"). How can I make csh see my variables as integers?

thanks in advance!
Reply With Quote
Forum Sponsor
  #2  
Old 01-22-2008
Registered User
 

Join Date: Jan 2008
Posts: 21
Your code have the syntactical errors

if [ $a -ge $b ]
then
echo $a
fi



Enjoy....
Anji
Reply With Quote
  #3  
Old 01-22-2008
Registered User
 

Join Date: May 2007
Posts: 27
Quote:
Originally Posted by Anji View Post
Your code have the syntactical errors

if [ $a -ge $b ]
then
echo $a
fi



Enjoy....
Anji
im using csh, this has always been the form of if that i have been using...
Reply With Quote
  #4  
Old 01-22-2008
Registered User
 

Join Date: Nov 2007
Posts: 85
You should use greater than symbol

Quote:
Originally Posted by Deanne View Post
hi, im trying to compare two variables in csh to put in an if statement, eg:

set a = $firstnum
set b = $secondnum
if ($a -ge $b) echo $a

But I get an error ("if: Expression syntax"). How can I make csh see my variables as integers?

thanks in advance!
if ($a > $b) echo $a
Reply With Quote
  #5  
Old 01-22-2008
Registered User
 

Join Date: May 2007
Posts: 27
thanks ranjithpr! it works. it was my first instinct to do that but the "-gt" was what the man pages indicate. i should have tried that one.
Reply With Quote
  #6  
Old 01-22-2008
Registered User
 

Join Date: Jan 2008
Posts: 21
if ( $a -ge $b) then
echo $a
endif
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0