LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 10-30-2010, 12:27 PM   #1
tinman47
LQ Newbie
 
Registered: Oct 2010
Posts: 1

Rep: Reputation: 0
Exclamation 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?
 
Old 10-30-2010, 12:49 PM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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.
 
Old 10-30-2010, 03:36 PM   #3
RogerBeep2010
LQ Newbie
 
Registered: Oct 2010
Posts: 4

Rep: Reputation: 0
Have you looked at the talk command? it may be what your looking for?
 
Old 10-30-2010, 04:20 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by RogerBeep2010 View Post
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.
 
Old 10-30-2010, 06:47 PM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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.
 
Old 10-30-2010, 07:24 PM   #6
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
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.)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Variables and Mkvextract in a bash script and a good resource for bash help? gohmifune Linux - General 9 04-13-2011 08:37 AM
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 06:00 AM
Bash script to create bash script jag7720 Programming 10 09-10-2007 07:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:46 AM.

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