The UNIX and Linux Forums  

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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-15-2008
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.
Reply With Quote
Forum Sponsor
  #2  
Old 05-15-2008
era era is offline
Herder of Useless Cats
 

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

Join Date: May 2008
Posts: 53
Quote:
>&2
i get it all bar that piece of code... what does it do?
Reply With Quote
  #4  
Old 05-15-2008
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.
Reply With Quote
  #5  
Old 05-15-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Of course I forgot the dollar sign on $MONTH ... blush. Sorry about that.
Reply With Quote
  #6  
Old 05-15-2008
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.
Reply With Quote
  #7  
Old 05-15-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Code:
while true; do
  echo Enter month
  read MONTH
  case $MONTH in ...ok...) break;;
     *) echo Invalid month name, try again >&2 ;;
  esac
done

grep $5 "$MONTH" tempfile >tempmonth
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 02:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0