LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-08-2008, 06:11 PM   #1
jakeo25
LQ Newbie
 
Registered: Jan 2008
Location: Boulder, CO
Distribution: Ubuntu Gusty / Fiesty
Posts: 7

Rep: Reputation: 0
Getting asynchronous user input in BASH


Hello

I have a BASH script running and would like to stop, without using Ctrl-C (this shuts down the entire script, which is not desired). So I need a clean exit from a running function. The bash built-in 'read' only accepts user input when prompted, and has a minimum of 1 second wait. It is not as 'clean' as I'd like ...(just hold down a key until the function execution catches up to the read ).

So here is what I would like: if the user presses a key at ANY time while a particular function is running, this key stroke would be caught and 'remembered'. The function would periodically check a variable or external event inside this loop, then do a clean exit from the function.

Any key should work, but a specific escape sequence like Ctrl-<something> would be fine.

Thanks in advance.

sed s|jake|Superjake|g
 
Old 05-08-2008, 06:22 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
Depending on how the logic of your program handles the asynchronous input you might be able to do what you want with the trap command.

http://linux.die.net/man/1/trap

Another approach would be to make the asynchronous read a separate thread which signals the main thread when input has been received.

---------------------
Steve Stites
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
User input into Bash scripts and checking validity of user input?? helptonewbie Programming 8 07-07-2008 06:40 PM
Bash Y/N user input zcrxsir88 Programming 11 04-16-2008 11:35 AM
Bash scripting and user input Woodsman Slackware 13 11-02-2005 02:20 PM
mask user input in a bash script PlatinumRik Linux - Software 1 06-15-2004 10:06 AM
User input using a BASH script... causticmtl Programming 5 07-13-2003 09:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration