03-05-2009
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?
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I'd like to write a shell script that will enter '1', for example. How
do you do that?
You know, so instead of writing
echo "Enter 1 or 2"
read onetwo
and waiting for the user to enter a 1 or 2,
I'd like the script to act like someone entered a 1, or 2. Is there a
hex value for the... (1 Reply)
Discussion started by: jpprial
1 Replies
2. UNIX for Dummies Questions & Answers
Hi,
Whenever i press the backspace key, a new line appears, i.e. it works like a enter key. :confused:
Thanks (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies
3. Shell Programming and Scripting
Hi,
I'm porting an install script from AIX to Red Hat (2.6.18-164.el5 #1 SMP)
I have this script working in both AIX and HP-UX.
The script is a wrapper for a Micro Focus Server Express install program. It responds to the install program questions with a here-now list. Responses includes... (14 Replies)
Discussion started by: duker61
14 Replies
4. Shell Programming and Scripting
hi experts
Question in perl
i'm creating a script to take from user a different inputs one of them is the carriage return .. so that i want to make an if condition if the user hit enter key the user will go to previous step
it something like that
chomp ($input = <STDIN>);
if ($input =~... (3 Replies)
Discussion started by: doubando
3 Replies
5. Shell Programming and Scripting
Hi I'm trying to create a basic script that pauses for user input to verify a file name before generating the output.
I have numerous SSL certificate files which I am trying to determine the expiry date so what I'm trying to do is write a script so that is pauses to request the name of the .pem... (9 Replies)
Discussion started by: Buddyluv
9 Replies
6. Shell Programming and Scripting
have three big data file, however I just need to see the mentioned below one line form the all the file which has SERVER_CONNECTION Value
File 1
export SERVER_CONNECTION=//dvlna002:10001/SmartServer
File2
export SERVER_CONNECTION=///SmartServer
File3
export... (1 Reply)
Discussion started by: Nsharma3006
1 Replies
7. Shell Programming and Scripting
hi,
i've bash script thats working...
but now i need to add a line....that prompts for user input....like yes and 1 as complete install....
so here's how it looks...
$ cd 9200 (cd into directory)
$./install (hv to type ./install to run install then ask for)
----do you want to... (4 Replies)
Discussion started by: kernel11
4 Replies
8. Shell Programming and Scripting
Hi all,
I have a little problem with my shell script (reading user input, save user input to variable, invisible characters in the log file :()
printf "1. What's your file path?"
/path/to/my/file
read -e FILE
I have invisible characters in my log file (e.g. <ESC> or ^G) when I'm... (3 Replies)
Discussion started by: splendid
3 Replies
9. Shell Programming and Scripting
I am looking for a way to start a script and have it prompt for a password that will be used later on in the script to SSH to another host and to SFTP. I don't want the password to be hard coded. Below is my script with the actual IP's and usernames removed.
#!/usr/bin/expect -f... (2 Replies)
Discussion started by: jbrass
2 Replies
10. Shell Programming and Scripting
Hey All,
I am writing one script using expect, that script which is used in spawn will accepts only 1. Enter 2. Ctrl+c
Press Control-C to exit, Enter to proceed.
Could some one share some thoughts to send the above user inputs in linux expect block ?
Thanks,
Sam (0 Replies)
Discussion started by: SCHITIMA
0 Replies
LEARN ABOUT MOJAVE
menu_mark
menu_mark(3X) menu_mark(3X)
NAME
menu_mark - get and set the menu mark string
SYNOPSIS
#include <menu.h>
int set_menu_mark(MENU *menu, const char *mark);
const char *menu_mark(const MENU *menu);
DESCRIPTION
In order to make menu selections visible on older terminals without highlighting or color capability, the menu library marks selected items
in a menu with a prefix string.
The function set_menu_mark sets the mark string for the given menu. Calling set_menu_mark with a null menu item will abolish the mark
string. Note that changing the length of the mark string for a menu while the menu is posted is likely to produce unhelpful behavior.
The default string is "-" (a dash). Calling set_menu_mark with a non-NULL menu argument will change this default.
The function menu_mark returns the menu's mark string (or NULL if there is none).
RETURN VALUE
The function menu_mark returns a pointer (which may be NULL). It does not set errno.
The function set_menu_mark may return the following error codes:
E_OK The routine succeeded.
E_BAD_ARGUMENT
Routine detected an incorrect or out-of-range argument.
E_SYSTEM_ERROR
System error occurred (see errno).
SEE ALSO
curses(3X), menu(3X).
NOTES
The header file <menu.h> automatically includes the header file <curses.h>.
PORTABILITY
These routines emulate the System V menu library. They were not supported on Version 7 or BSD versions.
AUTHORS
Juergen Pfeifer. Manual pages and adaptation for new curses by Eric S. Raymond.
menu_mark(3X)