The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
awk user input gefa Shell Programming and Scripting 17 10-30-2007 05:01 AM
Restricting the user *LINUX RED HAT* vakharia Mahesh UNIX for Dummies Questions & Answers 4 03-07-2007 12:29 PM
Getting user input stevefox Shell Programming and Scripting 3 02-16-2007 02:09 AM
user input date gundu Shell Programming and Scripting 10 03-21-2005 03:50 PM
Accepting User Input scott78 Shell Programming and Scripting 1 01-13-2004 02:54 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 08-08-2006
dhananjayk dhananjayk is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 12
Red face 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 (permalink)  
Old 08-09-2006
zhou zhou is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 8
Post

Why not try to use the regular expressions?
It's just the thing for you.
  #3 (permalink)  
Old 08-09-2006
dhananjayk dhananjayk is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 12
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 (permalink)  
Old 08-09-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
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 (permalink)  
Old 08-09-2006
zhou zhou is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 8
Smile

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}
Closed Thread

Bookmarks

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:50 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0