if condition-integer expression expected


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting if condition-integer expression expected
# 1  
Old 01-06-2012
if condition-integer expression expected

Hi ,

getting error in below code

integer expression expected. its due to floating point. plz help me to solve this


Code:
 
ADV1=94.3
Quantity=96.3
if [ $Quantity -eq $ADV1 ]; then
    echo "quantity is greter"
fi

# 2  
Old 01-06-2012
Code:
$ echo "" | nawk -v ADV1=94.3 -v Quantity=96.3 '{if(ADV1<Quantity){print "Quantity is greater"}}'
Quantity is greater


Last edited by jayan_jay; 01-06-2012 at 02:59 AM.. Reason: code ..
# 3  
Old 01-06-2012
Code:
ADV1=99.3
Quantity=96.6
echo "adv1: $ADV1"
echo "Quantity : $Quantity"
if [ $(echo "$ADV1 > $Quantity "|bc) -eq 1 ] ; then
echo "$ADV1 is greter"
else
echo "$Quantity is greater"
fi


Last edited by Franklin52; 01-06-2012 at 03:26 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 01-06-2012
Try this
Code:
ADV1=94.3
Quantity=96.3
if [ $Quantity -gt $ADV1 ]; then
    echo "quantity is greter"
fi


Last edited by tene; 01-06-2012 at 02:59 AM..
# 5  
Old 01-06-2012
hey last time i checked -gt, -eq, -lt etc are used for integer comparison and !=, == etc are used for string comparison.... how can a string compare -gt (greater than) or -lt (less than)

Code:
http://www.freeos.com/guides/lsst/ch03sec02.html

# 6  
Old 01-06-2012
Quote:
Originally Posted by vivek d r
hey last time i checked -gt, -eq, -lt etc are used for integer comparison and !=, == etc are used for string comparison.... how can a string compare -gt (greater than) or -lt (less than)

Code:
http://www.freeos.com/guides/lsst/ch03sec02.html

It was a typo. I corrected.
# 7  
Old 01-06-2012
Oh okay... :-) it got me all confused...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Integer expression expected

Hello , This is the piece of the code which is giving me trouble if ;then exit_proc "${SOURCEDIR}/${OUT_FILE} does not exists or not readable" 2 else word_count=`wc -l < ${SOURCEDIR}/$OUT_FILE` fi if ;then exit_proc "Word_count is more than allowed limit" 1 else... (6 Replies)
Discussion started by: Sri3001
6 Replies

2. Shell Programming and Scripting

Integer expression expected

Hi, I am getting the below error while comparing the month of a file to current month. I am using ls -lrth to get the month of that file and while using the if else condition i am getting the below error.. a1=`ls -lrth abc.txt | awk '{print substr($6,1,3)}'` This gives me the month from... (1 Reply)
Discussion started by: jaituteja
1 Replies

3. Shell Programming and Scripting

Integer expression expected

I need some help with this if but then it says line 11: I don't know what I'm doing wrong (1 Reply)
Discussion started by: margg
1 Replies

4. Shell Programming and Scripting

Integer expression expected

hi Guys, when i run the below script its showing error "integer expression expected" script pasted below: #!/bin/sh for i in {1..$2} do if then scp server1:/root/file.2012-$1-0$i . else scp server1:/root/file.2012-$1-$i . fi done (8 Replies)
Discussion started by: ganga39
8 Replies

5. Shell Programming and Scripting

Integer expression expected

Newb here echo "$yesterdaysclose" echo "$close" if ; then echo "stocks moving up" elif ; then echo "stock is moving down" else echo "no change" fi seems to evaluate the floating decimal correctly however returns ./shellscript1.sh: line 17: [: : integer expression expected... (3 Replies)
Discussion started by: harte
3 Replies

6. Shell Programming and Scripting

if condition error: integer expression expected

I am trying to run following condition with both variables having numeric values "1,2,3" if ;when i run it i get following error: $NEW_STATE: integer expression expected Please correct me where I'm doing wrong. I'm trying to check either New State is greater or Old state.... (0 Replies)
Discussion started by: kashif.live
0 Replies

7. UNIX for Dummies Questions & Answers

Integer Expression Expected!?!?

Ok, so I am beggining a script to factor the time difference from when a user logs on to current time but before I can even get too far I am getting the INTEGER EXPRESSION EXPECTED error. Can someone tell me what I am doing wrong? lhour=$(who | grep "$1" | cut -c30,31); lmin=$(who | grep "$1"... (1 Reply)
Discussion started by: losingit
1 Replies

8. Shell Programming and Scripting

Integer expression expected: with regular expression

CA_RELEASE has a value of 6. I need to check if that this is a numeric value. if not error. source $CA_VERSION_DATA if * ] then echo "CA_RELESE $CA_RELEASE is invalid" exit -1 fi + source /etc/ncgl/ca_version_data ++ CA_PRODUCT_ID=samxts ++ CA_RELEASE=6 ++ CA_WEEK_NO=7 ++... (3 Replies)
Discussion started by: ketkee1985
3 Replies

9. Shell Programming and Scripting

:integer expression expected

Hi, echo $i until || do read NUM if && ; then printf "$FBOLD\nInvalid number, please enter valid backup number: $FREG" fi done Getting below error : ./import_location.sh: line 234: [: : integer expression expected ./import_location.sh: line 234: [: :... (5 Replies)
Discussion started by: milink
5 Replies

10. Shell Programming and Scripting

Integer Expression Expected

Cannot figure out what the error is on line #10 I was trying to change my login prompt though I've success with that this shows up as well. Here's what I have (1 Reply)
Discussion started by: moonunit
1 Replies
Login or Register to Ask a Question