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
limiting failed logins to three csaunders HP-UX 1 10-18-2007 10:56 AM
Aplication user and kernel mode (data access) Brendan Kennedy High Level Programming 1 05-27-2007 06:45 PM
AIX v.5.1 - system and user data backup Sezgin AIX 5 01-08-2007 06:29 AM
Limiting length of user in while creating user Satya Mishra AIX 2 04-15-2005 03:40 AM
Limiting access misha UNIX for Dummies Questions & Answers 4 02-24-2001 07:25 AM

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 Rate Thread Display Modes
  #1 (permalink)  
Old 05-15-2008
amatuer_lee_3 amatuer_lee_3 is offline
Registered User
  
 

Join Date: May 2008
Posts: 53
limiting data inputs for the user

if my user has to enter the name of months to carry out a search how can I limit the input values to only the month names and nothing else?

so far my input criteria for the user is this:

Quote:
echo " "
echo "Enter the month in which you wish to search
(Please enter months in the form of Jan, Feb, Mar, etc...): "

read MONTH

grep $5 "$MONTH" tempfile > tempmonth
i would like it so the user can only enter the months in the way i have stated. otherwise they would get an error message.
  #2 (permalink)  
Old 05-15-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Code:
case MONTH in Jan|Feb|Mar|... you get the idea ...|Dec);; 
  *) echo Invalid month name, play again? >&2 ;; esac
  #3 (permalink)  
Old 05-15-2008
amatuer_lee_3 amatuer_lee_3 is offline
Registered User
  
 

Join Date: May 2008
Posts: 53
Quote:
>&2
i get it all bar that piece of code... what does it do?
  #4 (permalink)  
Old 05-15-2008
Danny.Chouinard Danny.Chouinard is offline
Registered User
  
 

Join Date: May 2008
Posts: 21
>&2 re-directs the output to file descriptor 2, which is called "Standard error", a channel used for outputting errors usually.

It's common unix practice.
  #5 (permalink)  
Old 05-15-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Of course I forgot the dollar sign on $MONTH ... blush. Sorry about that.
  #6 (permalink)  
Old 05-15-2008
amatuer_lee_3 amatuer_lee_3 is offline
Registered User
  
 

Join Date: May 2008
Posts: 53
Code:

echo " "
echo "Enter the month in which you wish to search
(Please enter months in the form of Jan, Feb, Mar, etc...): "

read MONTH

case $MONTH in [Jj]an|[Ff]eb|[Mm]ar|[Aa]pr|[Mm]ay|[Jj]un|[Jj]ul|[Aa]ug|[Ss]ep|[Oo]ct|[Nn]ov|[Dd]ec);; 
  *) echo "Invalid month name" ;; 
esac

grep $5 "$MONTH" tempfile > tempmonth
people are inputting data in this loop. i am trying to validate this loop so only months are entered. if the user enters the wrong data how do i loop it back so the user has to enter the month again. this is not the start of my code so using "start over" will not work.
Closed Thread

Bookmarks

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 12:57 PM.


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