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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is there a function to know if a variable is a number 1

Status
Not open for further replies.

cantubas

Programmer
Jan 8, 2004
45
FR
is there a function to know if a variable is a number or no ???

to know if a variable is a number I do:
if (( parametres = $parametres + 0 ))
then
echo "it's a number"
else
echo "it is not a number"
fi

... does another solution exist?
 
With ksh, you can do :

Code:
if [[ "$parametres" = +([0-9]) ]]
   then  echo "it's a number"
   else  echo "it is not a number"
fi


Jean Pierre.
 
In the Korn shell you can force a variable to only accept numeric characters...
Code:
typeset -i parametres
From that point on, it will only accept integer values.

Hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top