Anyone know the code to test for bad numbers?
For example in ksh...
Want the user to input an integer, but they input characters.
read number
while (number = letter)
read number //until valid number is inputted
thx for any help!!
Anyone know the code to test for bad numbers?
For example in ksh...
Want the user to input an integer, but they input characters.
read number
while (number = letter)
read number //until valid number is inputted
thx for any help!!
Use egrep to test...
read foo
echo "${foo}" | egrep "^[0-9]+$" >/dev/null 2>&1
if [ "$?" -eq "0" ]; then
echo "Yay"
else
echo "Nay"
fi
Cheers
ZB
This looks like a home work problem for me. Please read the Rules before posting.
Just a hint for your problem. Perform a arithmetic operation on your input. If it succeeds then numeric else it is non numeric.
Thanks Bob
works great