Re: How to determine integer?



2010-03-13, Decare skribis:

Is there any to determine whether a string
is a integer or not? For example,

read s
if [ ... ]; then
do something
else
do another
fi


I came across this kind of hack:

is_int() {
printf "%d" $1 > /dev/null 2>&1
return $?
}

read s
if is_int "$s"; then
echo "$s is an integer."
else
echo "$s is not an integer."
fi

--
kasmra
:wq
.