PDA

View Full Version : Numeric check


mirage
11-16-02, 06:11
I am trying to read a variable

read $2

how can I check whether the entered string is a number?

Thanks.

Damian Ibbotson
11-18-02, 13:16
echo $yourvar | grep "^[0-9][0-9]*$" && print numeric || print non-numeric

pstireman
06-25-03, 14:24
Here is another way to do it. This way will check decimals as well as whole numbers.

let TST=$1*1 && print $1 numeric || print $1 non-numeric 2>/dev/null