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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk/sed - getting string instead of number hrwath Shell Programming and Scripting 2 03-24-2008 07:26 AM
number of occurences of a string siddu_chittari Shell Programming and Scripting 12 12-05-2006 01:09 AM
$A is a number / any other string? How to determine ? csaha Shell Programming and Scripting 2 02-21-2006 04:03 AM
How to format number/string in ksh GNMIKE Shell Programming and Scripting 2 07-03-2005 04:44 PM
shell to number and to string xiamin Shell Programming and Scripting 1 11-06-2001 08:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-10-2003
George_king George_king is offline
Registered User
  
 

Join Date: Sep 2003
Posts: 1
Question string to number

In the following script when I get SIZE1 and SIZE2, they are of type string. I can not do any mathematical operations on them. I wanted to find out if I can convert string in to Number. Thanks in Advance.

FILE1='/export/registry/incoming/reg.dmp'
FILE2='/export/registry/reg.dmp'

SIZE1=`ls -l $FILE1 | awk '{print $5}'`
SIZE2=`ls -l $FILE2 | awk '{print $5}'`

if [ $SIZE1 > $SIZE2 ]
then
echo $SIZE1 - $SIZE2
else
echo "The 1st file is smaller."
fi
  #2 (permalink)  
Old 09-10-2003
kowrip kowrip is offline
Registered User
  
 

Join Date: Sep 2003
Location: New Jersey
Posts: 32
You didn't mention which shell you are using. Form Bourne shell or bash shell, the following comparison operators exist for comparing integer values:

int1 -eq int2 True if integer one is equal to integer two
int1 -ge int2 True if integer one is greater than or equal to integer two
int1 -gt int2 True if integer one is greater than integer two
int1 -le int2 True if integer one is less than or equal to integer two
int1 -lt int2 True if interger one is less then interger two.
int1 -ne int2 True if integer one is not equal to integer two

So, you should be able to do something like:

if [ $SIZE1 -gt $SIZE2 ]
then
...
else
...
fi
  #3 (permalink)  
Old 09-10-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
And if you actually want the result of $SIZE1 - $SIZE2, you'll have to replace

echo $SIZE1 - $SIZE2

with:

echo `expr $SIZE1 - 500`
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 07:47 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