# is_digit: This function matches an all digits regular expression
# against an argument and returns 1 if the argument is digits else 0
# if isn't.
# Note the use of nawk. Use gawk for the Bash shell.
function is_digit
{
echo $1|nawk ' { if ($0 ~ /^[0-9]+$/)
print 1
else
print 0 } '
} # end is_digit
you can also use 'expr'
for example :
num=123
if expr "0$num" : "0[0-9]\+$" > /dev/null
then echo "Good"
else echo "Not numeric"
fi Jean Pierre.
Okay, I understand the numeric part, but what about the alpha. I am working with a single character. The tr command will translate from lower to uper, but how do I tell if the result is from A to Z? The test command does not seem to allow an alpha operator when doing a less or greater comparison.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.