![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|