|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Check if input is an integer or a floating point?
Hiii
I actually intent to check the integer or floating point number input by user i.e. 23, 100, 55.25, 12.50 ..etc. However, when someone input strings or alpha character, my program has to show invalid input.!! Is there any Unix shell script syntax can help me to check ? Thanking you |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
|
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
Are you expecting this. See the following shell script, It will check the given string is integer or float. Code:
echo "123" | grep "^[0-9]*$"
val=`echo $?`
if [[ $val == 0 ]]
then
echo "Given string is intiger"
else
echo "Invalide"
fi
echo "123.3" | grep "^[0-9]*[.][0-9]*$"
val=`echo $?`
if [[ $val == 0 ]]
then
echo "Given string is float"
else
echo "Invalide"
fiLast edited by ungalnanban; 03-11-2010 at 11:52 PM.. Reason: code alignment |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Floating point Emulator | pgmfourms | Programming | 1 | 04-22-2009 07:48 AM |
| Floating Point Exception | Mandar123 | Linux | 3 | 01-22-2009 08:51 AM |
| Floating point error in C | Hara | Programming | 2 | 06-18-2008 05:43 AM |
| Replace floating-point by integer in awk | smadonald1 | Shell Programming and Scripting | 7 | 01-31-2008 06:39 AM |
| floating point addition | ravi raj kumar | Shell Programming and Scripting | 8 | 12-22-2006 01:47 AM |
|
|