Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-30-2010, 12:27 PM
|
#1
|
LQ Newbie
Registered: Oct 2010
Posts: 1
Rep:
|
Is this Bash script even possible? Help me out.
How do you catch user input while the script is running?
Or, how would you make two scripts run at the same time, but use input from one script to the other?
The program I'm trying to make, echos text on the screen continuously, but while thats happening, I want the user to be able to input something, so the program can detect the input and display something else. So I thought maybe I could make two scripts run to do each task. Can anyone solve my problem?
|
|
|
10-30-2010, 12:49 PM
|
#2
|
Moderator
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
|
I think this a case for a more advanced language than the bash scripting language. For me it seems to be a perfect case for a language that have bindings to the ncurses library, so that you can have different input and output areas on the screen. Maybe Python, Ruby or something similar.
|
|
|
10-30-2010, 03:36 PM
|
#3
|
LQ Newbie
Registered: Oct 2010
Posts: 4
Rep:
|
Have you looked at the talk command? it may be what your looking for?
|
|
|
10-30-2010, 04:20 PM
|
#4
|
Moderator
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
|
Quote:
Originally Posted by RogerBeep2010
Have you looked at the talk command? it may be what your looking for?
|
talk is a chat program, I don't see the point why you recommend it here.
|
|
|
10-30-2010, 06:47 PM
|
#5
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
Quote:
Originally Posted by TobiSGD
talk is a chat program, I don't see the point why you recommend it here.
|
I haven't used talk, but assuming it's a terminal-based chat program, I imagine it was suggested as a reference--some code to look at. The OP said he wanted to get user input and simultaneously stream text to the screen. So, at a basic level, a terminal-based chat program would accomplish what the OP wants.
That said, I imagine talk is not written in a scripted language, but rather a compiled one. So, it may not be a very useful reference.
|
|
|
10-30-2010, 07:24 PM
|
#6
|
Senior Member
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187
|
Your two script idea can be made to work. The simplest way to accomplish your objective might be to have the "echo" program periodically check for the existence of some file, and the "read" program create the file when the input is read. The '"echo" program would, of course, delete the file after it processed it. (You could even use the file to pass information from the "read" program to the "echo" program.)
Look at man test for various file existence directives. Note also the sleepcommand that you can use so your test loop won't "eat" all your CPU cycles.
You might also want to look at pipes that can be used to connect separate processes. If you aren't restricted to using bash, you might find the discussion (and implementation) of bi-direction pipes in gawk interesting. (Note that bi-directional pipe is a gawk extension, not available in standard (POSIX) awk.)
|
|
|
All times are GMT -5. The time now is 04:46 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|