Bash scritping: more hints for working with numbers
As an addendum to my first post about bash scripting and numbers here are some more nice information.
* Check if $VAR is a positive integer:
if echo "$VAR" | egrep --null "^[[:digit:]]+$" > /dev/null ; then
echo Integer: $VAR
else
echo $VAR isn't an integer.
fi
* Check if $VAR is a positive real number:
if echo "$VAR" | egrep --null "^[[:digit:]]+(\.[[:digit:]]+)*$" > /dev/null ; then
echo Real number: $VAR
else
echo $VAR isn't a real number.
fi
Enjoy!
No comments:
Post a Comment