Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

test command is not working

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-04-2006
zam zam is offline
Registered User
 
Join Date: Jun 2005
Last Activity: 14 June 2017, 1:02 AM EDT
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
test command is not working

#!/bin/ksh
size=3978132853
limit=100
if [ $size -gt $limit ];then
echo exceeded limit
fi

This does not work though if i reduce 3978132853 to 397813285 it works any ideas and work around appreciated

(SunOS 5.9 Generic_117171-02 sun4u sparc SUNW,Ultra-80 )
Sponsored Links
    #2  
Old Unix and Linux 07-04-2006
thestevew thestevew is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 11 July 2008, 4:53 AM EDT
Location: South Yorkshire, UK
Posts: 114
Thanks: 0
Thanked 1 Time in 1 Post
Looks like integer overflow in the test. I get the same result on SunOS 5.6 but ksh on Aix 5.3 gives the right answer.

You could use bc to get round it, just test for a negative result after subtracting limit from size


Code:
size=3978132853
limit=100 
typeset -L1 res
res=$(($size - $limit))
if [ ! "$res" = "-" ]; then
  print exceeded limit
fi

Sponsored Links
    #3  
Old Unix and Linux 07-04-2006
zam zam is offline
Registered User
 
Join Date: Jun 2005
Last Activity: 14 June 2017, 1:02 AM EDT
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
Linux Thanks for the prompt reply. Your solution works just fine.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help! command working ok when executed in command line, but fails when run inside a script! 4dirk1 Shell Programming and Scripting 4 12-02-2010 05:47 AM
How to check weather a string is like test* or test* ot *test* in if condition johnjerome Shell Programming and Scripting 5 02-18-2010 05:38 AM
Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d Max89 Shell Programming and Scripting 1 11-25-2009 01:08 PM
Test command name nck Programming 3 02-12-2009 12:22 PM
How i test the UDP port is working? summerpeh Solaris 2 11-07-2008 05:15 AM



All times are GMT -4. The time now is 12:49 AM.