Check if variable is numeric or string
Posted on 2003-11-20
I have a problem in a shell program where I do errorchecking.
I ask a returnvalue from the database, which usually is a number, and this goes to a variable.
Now, I want to know if the returnvalue is a number or a string (the erromessage)
A sample of what I have:
tail -2 $log > $templog
head -1 $templog | read returnstatus
if [ $returnstatus > 0 ]
This goes well when $returnstatus is 0 or 20000 but, of course, not when $returnstatus is for example 'Arithemic overflow'
I also tried
if [ "$returnstatus" > "0" ]
but still no succes.
what I want is something like:
if $returnvalue between 0 and 999999
Or a check if $returnstatus is a number or not, if that is possible.
So, how do I do this in ksh script?
I work om HP-UX.