![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| check the input | Shilpi | UNIX for Dummies Questions & Answers | 1 | 03-04-2008 05:26 AM |
| check input = "empty" and "numeric" | geoffry | Shell Programming and Scripting | 6 | 12-13-2007 02:12 AM |
| How to check for a valid numeric input | Vijayakumarpc | Shell Programming and Scripting | 1 | 08-04-2007 05:34 AM |
| How to prompt for input & accept input in ONE line | newbie168 | Shell Programming and Scripting | 2 | 09-27-2005 02:02 AM |
| What can i do to check that the input is all alphabet.. ? | XXXXXXXXXX | Shell Programming and Scripting | 4 | 02-19-2002 04:09 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Check on Input
HI all,
I would like to know how the user can be restricted for entering only the number and not characters in sheel scripts.. Suppose code is like this echo 'Enter the number' read Value Now user may enter 'a' as value... But i want to disallow him for entering characters other than numbers. How can i do it... Is their anything like value=\^D Please specify Thanks |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
What shell are you using? If you are using ksh, you can use typeset -i. Here's how:
Code:
$ typeset -i a $ echo $a $ a=a $ echo $a 0 $ a=10 $ echo $a 10 - note: this is tested on FreeBSD. |
|
#3
|
|||
|
|||
|
Hi,
The code u send is working fine... Now it is not giving an error expr : as non-numeric argument I am working on Ksh But if i wanna do following $ User prompted -> Enter the number $ He enters -> b now instead of accepting 'b' ( as it is not an integer ) I want to clear that 'b' ...as follows and again prompt the user for entering the value $ User prompted -> Enter the number $ He enters -> b ( clear that 'b' or any character unless and until he enters integer ) $ User prompted -> Enter the number Thanks.. Quote:
|
|
#4
|
||||
|
||||
|
A different approach.
Code:
echo "enter string: \c" read a A=$(echo $a |tr -d '[0-9]*') if [ -z $A ]; then echo number! else echo not number! fi |
||||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|