I have a form made it with a couple of text boxes, in which I input floating numbers and use this number to sum with other text box and put the result in a label.

I then input the values of the text boxes to a variable (xbiz and xbder) and I sum it for example I get then this result : xbiz = 5.2 xbder = 2.3

My problem is when one of the text boxes is empty (in blank) the script give me an error of "ILLEGAL FLOAT VALUE!" I mean if I am not input a value in any od the two variables

How can solve this problem?

Here is my code:

echo "FG 999999" >> $gui_in
echo "FONT cbr18" >> $gui_in
echo "BG 901010" >> $gui_in
echo "LABEL LOCATINES" >> $gui_in
echo "FG 101090" >> $gui_in
echo "FONT cbr18" >> $gui_in
echo "BG 708787" >> $gui_in

echo "TEXT xbiz X_BOT_IZQ" >> $gui_in
echo "TEXT xbder X_BOT_DER" >> $gui_in

set varx = `echo " $xbder + $xbiz" | bc -l`

#After calculate the values of the two variables (xbder + xbiz) I use the result in the following line:

COM display_layer,name=comp,display=yes,number=1
COM add_pad,attributes=no,**x=${varx},y=${varx}**,symbol=${sizefido},polarity=positive,\

If xbiz or xbder is empty, bc will complain (bash here)

$ echo "5.2 + " | bc -l
(standard_in) 2: syntax error

You're going to need something like (untested)

if (! $?xbiz) set xbiz = 0
set varx = `echo " 5.2 + $xbiz" | bc -l`
if (! $?xbder) set xbder = 0
set vary = `echo " 5.2 + $xbder" | bc -l`
  • Hi Glenn, I am still getting the illegal floating point error" I realize that the number "5" that I adding or summing is not 5, rather is 5.2 so the formula is going to be : set varx = echo " 5.2 + $xbiz" | bc -l Do you have another idea how to solve this?? – Dany Apr 22 '14 at 15:54
  • What is the content of the xbiz variable? – glenn jackman Apr 22 '14 at 16:26
  • Hi Glenn: the content of the xbiz variable is coming from a input text boxes, generally are numbers like 2.4, 4.15,etc. my problems is when the text box is empty or "0" there I get the error illegal float point value!! – Dany Apr 22 '14 at 17:59
  • Well, in those cases, you have to change the value. – glenn jackman Apr 22 '14 at 18:00
  • How do I change the values Gelnn? I am so new in shell script, how do I get rid of the illegal float point error, thanks for your valuable help! – Dany Apr 22 '14 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.