View Single Post
Old 10-23-2013, 03:06 PM   #12
rkomar
Wizard
rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.rkomar ought to be getting tired of karma fortunes by now.
 
Posts: 2,986
Karma: 18343081
Join Date: Oct 2010
Location: Sudbury, ON, Canada
Device: PRS-505, PB 902, PRS-T1, PB 623, PB 840, PB 633
Quote:
Originally Posted by SIRSteiner View Post
Yes, but shell variables are always saved as string.

Regards
In this case they are. The sh_ivtool.app program is outputting string data to stdout.

Besides, numbers are only allowed to be integers in shell scripts, so trying to assign a floating point number like 2.9 to an integer wouldn't have worked right anyway. You should either handle the mantissa and the fractional parts separately, or use something like awk to deal with floating point numbers.

paolog, to make your code more bulletproof, you should be testing the return code of sh_ivtool.app before using the output. It's possible that someone can just hit the escape button in the middle of the dialog and it won't be outputting any proper string. So, as in the README.txt file:

Code:
NUM=`sh_ivtool -n "Enter a number:"`
if [ $? -eq 0 ]; then
  if [ "$NUM" > "0" ]; then
    echo It's bigger than 0!
  fi
fi
or, more concisely:

Code:
NUM=`sh_ivtool -n "Enter a number:"`
if [ $? -eq 0 -a "$NUM" > "0" ]; then
  echo It's bigger than 0!
fi
rkomar is offline   Reply With Quote