Read line with a single key press...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read line with a single key press...
# 1  
Old 03-31-2003
Read line with a single key press...

I would really like to have a script that will accept the key press from the user with out having to press the enter key afterwards.

i.e.
echo "Press Y to print \c"
read YesNo

At this point the user has to press the enter key to continue. Is there a way to accept the key press from the user, with out the enter key needing to be pressed afterwards?





Smilie
# 2  
Old 03-31-2003
# 3  
Old 04-01-2003
If you want it in perl with a GUI interface!

Quote:


use Tk;

#make a main window
$mainwindow = MainWindow -> new();


$mainwindow->Button(-text => 'Press Y to print',
-command => sub{command_button()}
)->pack;

MainLoop;

sub command_button {

#put yor command script here!

};
# 4  
Old 04-04-2003
If you're running non-interactively, ksh and bash can read one character at a time using read:
Code:
$ cat tmp.sh
#! /bin/ksh
while read -n1 char; do
print $char
done

$ echo test | ./tmp.sh
t
e
s
t

$

I can't get it to work interactively, though. I know it's not really what you're looking for in this case, but it might be of use in the future...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to detect key press in cgi shell script?

I want to detect key pressed in my .cgi web page, but it does not work even I found the code in other web site. My code is : #!/bin/sh #================================================= # PATH defination # ================================================... (2 Replies)
Discussion started by: Shuinvy
2 Replies

2. Shell Programming and Scripting

Show distinct values of a key from a single line

Hi All, I am newbie to linux. Can somebody help me with following requirement. I have one huge line. I have to find out particular key/value pair to see the distinct value of that key. Portion of the String:- <?xml version="1.1" encoding="UTF-8"?> <Data><Val Ti="1342750845538" Du="0"... (5 Replies)
Discussion started by: kmajumder
5 Replies

3. Shell Programming and Scripting

how to read multi line characters in a single column

Hi, I have file in which fields are pipe (|) separated and the record separator is new line (\n). But sometime I am getting a field value which is spread across multiple line. Basically I am getting a file from another system in the below format and needs to process the file and load data into a... (3 Replies)
Discussion started by: satyaatcgi
3 Replies

4. Shell Programming and Scripting

Press Any Key script sequence using bash - HELP

hi to all. im a newbie in unix shell scripts. i want to make a simple unix shell script using the bash shell that asks a user to press any key after a series of commands, or an x if he wishes to exit. here's a sample script that i made: #!/usr/bin/bash pause(){ /usr/bin/echo "\t\t Press... (3 Replies)
Discussion started by: booghaw
3 Replies

5. Shell Programming and Scripting

Read duplicate column, then generate a single line

Dear experts, How to generate the result listed below ? Input file: col1col2col3Aname1size1Aname2size2Aname3size1Bname4size3Bname5size5Cname6size8Cname7size6Cname8size9Cname9size11Cname10size16 What I want is: Aname1, size1name2, size2name3, size1Bname4,size3name5, size5Cname6,... (1 Reply)
Discussion started by: tojzz
1 Replies

6. Shell Programming and Scripting

Any key press causing logout from shell

Hi all! I have written a shell script which will invoke perl script infinitly in the background in a loop. Code will do as:Within while loop, perl script will be run in background, get the pid and notify pid in though mail. then wait for pid to be completed before going for next iteration. I am... (1 Reply)
Discussion started by: jramesh1
1 Replies

7. Shell Programming and Scripting

read -n1 -r -p "Press..." key / produces error in bash shell script

Hello! Sorry, for my not so perfect english! I want to stop bash shell script execution until any key is pressed. This line in a bash shell script read -n1 -r -p "Press any key to continue..." key produces this error When I run this from the command line usera@lynx:~$ read... (4 Replies)
Discussion started by: linuxinho
4 Replies

8. Shell Programming and Scripting

Need helpl in scripting read 2 lines and paste to one single line.

Hi All, I need to create script which will accept one file as i/p and give me o/p file described as below. 1) i/p log file named abc.log contents several lines but i am interested in lines like below. #FILE..... /oracle/XYZ/sapdata1/undo_7/undo.data7 #SAVED.... BACKINTID001 2) o/p... (4 Replies)
Discussion started by: paragp1981
4 Replies

9. Shell Programming and Scripting

Trap key press in a script

How can I trap a character press in the shell script. For eg:- I have a script runinng a infinite loops , I will need to quit if q is pressed. I have seen the traping the signal , but they give option only for traping the defined interrupt signals. But those does not help me here. (3 Replies)
Discussion started by: praveenbvarrier
3 Replies

10. UNIX for Dummies Questions & Answers

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 ; then clear echo "Sorry, that is an invalid choice!" exit fi I am using a KSH script in... (3 Replies)
Discussion started by: jagannatha
3 Replies
Login or Register to Ask a Question