restricting user input as required


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting restricting user input as required
# 1  
Old 08-08-2006
Power restricting user input as required

Hi,

I want the user to enter only numeric values and also he should only enter
2 digits only ( eg 23 or 23 or 03 any 2 digits)

For the above purpose how should i declare my variable ?
integer value

if I read 03 in variable value then it gives me error ...also user can enter n number of digits ..how can i restrict it to only 2 digits ...

Thanks ...
# 2  
Old 08-09-2006
Java

Why not try to use the regular expressions?
It's just the thing for you.
# 3  
Old 08-09-2006
some problem

Quote:
Originally Posted by zhou
Why not try to use the regular expressions?
It's just the thing for you.
i can use regular expressions to check whether entered string is numeric or character one ... but how can i restrict it to 2 or 3 digits only ?
# 4  
Old 08-09-2006
From man sh

Code:
       read [-ers] [-u fd] [-t timeout] [-a aname] [-p prompt] [-n nchars] [-d
       delim] [name ...]
              -n nchars
                     read returns after reading nchars characters rather  than
                     waiting for a complete line of input.

I couldnt find anything similiar for ksh. Hmm...

Or a more generalized way would be to see what this post holds - making a .sh wait for user input
# 5  
Old 08-09-2006
Bug

Quote:
Originally Posted by dhananjayk
i can use regular expressions to check whether entered string is numeric or character one ... but how can i restrict it to 2 or 3 digits only ?
the express is \d{2,3}
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Best Alternative for checking input parameter contains required value or not

Any good way to check if code has the required output # /sbin/sysctl net.ipv4.icmp_echo_ignore_broadcasts net.ipv4.icmp_echo_ignore_broadcasts = 1 /sbin/sysctl net.ipv4.icmp_echo_ignore_broadcasts | grep "= 1" net.ipv4.icmp_echo_ignore_broadcasts = 1 What I can think of is above, and it... (16 Replies)
Discussion started by: alvinoo
16 Replies

2. Post Here to Contact Site Administrators and Moderators

Moderator input required please

We have been told to use this method for contacting moderators (rather than PM). Can any moderator please checkout what member 'buyvpn' is up to. Thanks. ---------- Post updated at 11:19 AM ---------- Previous update was at 11:15 AM ---------- Advertising services on at least one post. (1 Reply)
Discussion started by: hicksd8
1 Replies

3. UNIX for Dummies Questions & Answers

Create a file with input values required

Hi Guys Please can you help me to create a file using the following inputs 2351 first input 2339 second input all this rows need to have the value 0 in front 2338 third input 2333 fourth input all this rows need to have the value 1 in front count all the rows in the file and insert the... (10 Replies)
Discussion started by: jiam912
10 Replies

4. Shell Programming and Scripting

How to get the user input recursively until the user provides valid input

Hi, echo "Enter file name of input file list along with absolute path : " read inputFileList if then for string in `cat inputFileList` do echo $string done else echo " file does not exist" fi From the above code, if the user enters a invalid file... (1 Reply)
Discussion started by: i.srini89
1 Replies

5. UNIX for Dummies Questions & Answers

Restricting Usage of Setuid Programs to the Admin User In MacOsx

This is a quote from the Apple security configuration (you can download it from Apple) " Using ACLs to Restrict Usage of Setuid Programs The ACL feature of Mac OS X can also be used to restrict the execution of setuid programs. Restricting the execution of setuid programs to administrators... (3 Replies)
Discussion started by: Vera
3 Replies

6. AIX

restricting sftp and ssh for a user

I want to know if there is any way to set up a users home directory access with a restricted shell and allow them to SFTP to the directory. I want to allow the user to SSH into their home directory but no where else on the AIX server. I also want the user to be able to SFTP files to their home... (1 Reply)
Discussion started by: daveisme
1 Replies

7. UNIX for Dummies Questions & Answers

Restricting a user to their home directory and below

I found this old closed thread: I can do these things, but how to I change someone's profile - where do I find the profile? I'm running Centos 5.6 ~~~~~~~~~ providing you have the password shell set to ksh, you can put this in his .profile: cd /opt/load alias -x cd=: (6 Replies)
Discussion started by: jjj0923
6 Replies

8. Shell Programming and Scripting

Input required for telnet in script

Guru, I am trying to use telnet in unix script. And it's asking password after executing telnet command in script. But I don't want to have manual intervention over there. So is it possible to pass password for telnet from script itself. What I am doing right now is something like this. ... (4 Replies)
Discussion started by: gander_ss
4 Replies

9. UNIX for Advanced & Expert Users

password required when using input redirection

Hello, I need to change user and run some commands by using a script. lets say, I'm using su - someuser << start password required -----> how can I enter the password here command 1 command 2 command 3 command 4 start While trying to run this I got the following message: "standard... (2 Replies)
Discussion started by: Alalush
2 Replies

10. UNIX for Dummies Questions & Answers

Restricting the user *LINUX RED HAT*

Hats of to all the members for providing the detailed guidence to the newbe !! :o I am working on Red Hat LINUX plateform, where the number of users are more that 50. The problem I m facing is that all the user are opening the virtual terminals and leave it unattended for hours together and... (4 Replies)
Discussion started by: vakharia Mahesh
4 Replies
Login or Register to Ask a Question