Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Testing if an answer is a number

Status
Not open for further replies.

Larshg

Programmer
Mar 1, 2001
187
DK
Hi

I need to test an answer in a script is a number

something like this

print -n "Type a number : "
read number
if (test $number = xxxxx)
then
echo "great"
else
echo "this is not a number"
fi


the question is - what should i put insteed of xxxxx(if there is something)

The number can't be 4,9 it has to be a rounded up number


Thanks
 
Try this :
[tt]
if [[ $number = +([0-9]) ]]
then
echo "great"
else
echo "this is not a number"
fi
[/tt]

Jean Pierre.
 
Or something like this (in ksh):
print -n "Type a number : "
typeset -i number
rc=1;while (($rc));do read number;rc=$?;done

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top