![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl code to differentiate numeric and non-numeric input | Raynon | Shell Programming and Scripting | 11 | 08-04-2007 10:32 AM |
| validating data | joanneho | Shell Programming and Scripting | 1 | 10-08-2006 12:03 PM |
| Validating variables in shells script | DeepakXavier | Shell Programming and Scripting | 1 | 09-23-2005 10:32 AM |
| Validating $1 and $2 before using | nhatch | Shell Programming and Scripting | 6 | 09-17-2003 01:01 PM |
| validating dates | MizzGail | Shell Programming and Scripting | 2 | 03-05-2002 04:34 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
validating variables (numeric)
Hi
I need to get a user to enter a number (an exchange rate) into a script. I have the following: #!/bin/ksh echo "Enter exchange rate:" read EX_RATE if [ -z "`echo \"$EX_RATE\" | tr -d \"[:digit:]\"`" ] then echo "Well done - only numeric here" else echo "Not so well done - there is NON numeric stuff here!" fi This works fine except when I try to enter a decimal number when it exits because the decimal point is obviously non-numeric. I have looked at the other class keywords and there is not one that covers decimals. Can anyone help me out here? thanks Paul |
|
||||
|
try this
Code:
echo "Enter exchange rate:"
read EX_RATE
if [ -n "`echo \"$EX_RATE\" | sed -n "/^[0-9.]\{1,\}$/p"`" ]
then
echo "Well done - only numeric here"
else
echo "Not so well done - there is NON numeric stuff here!"
fi
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|