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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Pressing Enter (bash) Yakuzan Shell Programming and Scripting 34 03-03-2009 11:14 AM
Bash : how do i check the user input and make sure is only chracter or only number ? CheeSen Shell Programming and Scripting 7 09-07-2008 08:06 AM
Qmail requiring SMTP auth vertigo23 UNIX for Dummies Questions & Answers 0 12-22-2005 05:04 PM
Can i enter password with out user interaction kumar_d Shell Programming and Scripting 1 06-21-2005 03:21 AM
hit 'enter' with no user intervention jpprial UNIX for Dummies Questions & Answers 1 09-28-2001 01:05 PM

 
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
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 03-05-2009
deckard's Avatar
deckard deckard is offline
Registered User
  
 

Join Date: Jul 2002
Location: Ohio
Posts: 135
BASH: Any Way to Get User Input Without Requiring Them to Hit the Enter Key?

I'm working on making a menu system on an HP-UX box with Bash on it. The old menu system presents the users with a standard text menu with numbers to make selections. I'm re-working the system and I would like to provide something more akin to iterative search in Emacs.

I have a list of 28 objects in an array that I want to match against as they type. So lets say the first four elements are:

ALU
BOR
CAD
CHR


If the user started with an "a" they would automatically get ALU since there are no other A elements. If they typed "c" however, they would get CAD with CHR printed just beneath it until they either type "a", "h" or something else. If they type "a" as the next letter, they get CAD and CHR disappears from the list. It they type "h" as the next letter, they get CHR and CAD disappears from the list. If they type "x" for example, then they get a brief "No Match" message and return to "C".

My thought is that to pull this off I need something other than 'read' since that requires you to press the enter key. I need something that will capture the keystroke and append it to a variable like this:

Pass 1: (user enters C)

MATCH="C"
# code here to check the entry against the list in the array
echo $MATCH # This prints out "C"

Pass 2: (user enters A)

MATCH=$MATCH$ENTRY
# code here to check the entry against the list in the array
echo $MATCH # This prints out "CA"

Pass 3: (user presses backspace)

MATCH=${MATCH:0:$((${#MATCH}-1))}
# code here to check the entry against the list in the array
echo $MATCH # This prints out "C" again

Pass 4: (user enters X)

MATCH=$MATCH$ENTRY
# code here to check the entry against the list in the array
# no match so...
echo "No Match" ; sleep 2s ; clear
MATCH=${MATCH:0:$((${#MATCH}-1))}
echo $MATCH # This prints out "C"

Is this even a possibility in Bash or should I be looking elsewhere?
 

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 11:02 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