The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
to know about press button command doctor001 UNIX for Dummies Questions & Answers 1 04-02-2008 12:46 PM
how to find empty folders without using -empty lasse UNIX for Dummies Questions & Answers 7 01-16-2008 11:30 PM
TheOnlin Backup.com Offers Customers Free Trial - The Open Press (press release) iBot UNIX and Linux RSS News 0 07-29-2007 09:30 PM
Print to Any Windows Printer from DOS, Unix, Linux, legacy ... - Press World (press r iBot UNIX and Linux RSS News 0 07-02-2007 04:50 AM
Trying to capture empty variable. radhika UNIX for Dummies Questions & Answers 6 07-26-2005 11:50 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-06-2003
Registered User
 

Join Date: Oct 2002
Location: Auckland, NZ
Posts: 49
Capture an empty key press...

I am trying to test input from the user, if they press enter with out an Y or N. I have the characheter thing sorted but when it comes to a blank or empty key press I am having trouble.

if [ ${continue} = '' ]; then
clear
echo "Sorry, that is an invalid choice!"
exit
fi

I am using a KSH script in Solaris.

Thanks in advance.
Forum Sponsor
  #2  
Old 11-06-2003
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
use a loop such as this
until [ $INPUT = Y ]
do
do some stuff here
done
to check to see that your variable is set properly based upon what the user typed in. The loop will continue to be executed until condition is TRUE. This is useful when the expected input is a Yes/No queston or of similar type.
Or
check to see that the variable you use to capture standard input is actually set. You can do this by checking or an empty string. Your code was close but you were either using single quotes or were missing an end double quote.

echo " Enter Some Input Data: \c"
read INPUT

if [ ${INPUT} = ''" ]; then
clear
echo "Sorry, that is an invalid choice!"
exit
fi

Last edited by google; 11-06-2003 at 06:44 PM.
  #3  
Old 11-06-2003
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
You need to quote the input variable or use double square brackets...

if [ "$continue" = "" ]

OR

if [[ ${continue} = '' ]]
  #4  
Old 11-06-2003
Registered User
 

Join Date: Oct 2002
Location: Auckland, NZ
Posts: 49
Sorted, thanks very much google.


Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:52 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