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!

how to validate the value is digit pls ...

Status
Not open for further replies.

h3nd

Programmer
Jul 1, 2006
147
AU
Hi guys,

I have to tried to validate whether the value is digit. I have tried this one but it's not working.
Code:
 [[ "$f" == "[[:digit:]]" ]]

anyone can help me ??
Thx
 
Code:
[[ $f == [0-9] ]]

Ever think of buying the O'Reilly "Learning the Korn Shell" book? It would answer most of the questions you ask.
 
A portable way:
case $f in
*[!0-9]*) echo $f BAD;;
*) echo $f OK;;
esac

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thx guys,

kHz, the problem is my number could be many digits.

PHV, thx. but I think it's better using :
[[ $f == [0-9][0-9][0-9][0-9][0-9][0-9] ]]
 
It's better if you want a number with exactly 6 digits.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top