> pn] Thanks, that's elegant when I need to work only with
> integers. It works on SuSE 8.2 bash, but
> not Solaris 8 ksh. Odd.
If you want to check for numbers other than integers, you'll get
difficulties with shell pattern matching.
You could probably use grep -E:
echo -.2e+31 |grep -E
'^[+-]?([0-9]+\.?[0-9]*|[0-9]*\.[0-9]+)([eE][+-]?[0-9]+)?$'
This monster accepts things like '123', '+123.43e-3', '-2.', '.04E+5'
Note that Charles' script only accepts positive integers as well. If you
want to accept negative ints you could change it to this:
#!/bin/sh
ParseChar () {
case $1
in
[0-9]*)
if [ ${#1} -ge 2 ] ; then
ParseChar ${1#?}
fi ;;
*) NUMBER=NO ;;
esac
}
Parse () {
NUMBER=YES
case $1 in
[+-]*)
ParseChar ${1#?}
;;
*) ParseChar $1
;;
esac
}
Parse $1
echo "Number?: $NUMBER"
- Alex
-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps
------------------------------------------------------------------------
leaf-user mailing list: [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-user
SR FAQ: http://leaf-project.org/pub/doc/docmanager/docid_1891.html