LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-23-2006, 02:20 PM   #1
happy78
Member
 
Registered: Aug 2003
Posts: 50

Rep: Reputation: 15
Enter key in bashscript


Hello all,

Im writing this script (A) which launches another one (B), which asks for input. I am able to echo my answer to the input line of B, but within the script, it doesn't do anything because I don't know what is the equivalent of "Enter Key" in bash script.

In other words, I want my script (A) to execute "Enter Key" autotmatically after the echo.

any suggestion is greatly welcome. thank you all for your time and assistance

Happy
 
Old 03-23-2006, 03:50 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
This is--I hope--PART of the answer.

In real time, you type a command and hit enter---that is the signal to the shell to act on what you just typed.

In a program, script, whatever, you pass a word to a function and you get a similar result.

Maybe one way to think of it is that "enter" adds the CR character. When a text variable is created, the CR is included.

AGAIN--I am sure that my explanation is imprecise and impure....
 
Old 03-23-2006, 05:42 PM   #3
alexander_bosakov
Member
 
Registered: Mar 2006
Location: Plovdiv, Bulgaria
Distribution: OpenSuse 11.3
Posts: 55

Rep: Reputation: 15
Can you be more specific about what are you trying to do? 'echo' command sends CR by default, unless explicitly told not to do so with the '-n' option.
 
Old 03-23-2006, 06:04 PM   #4
happy78
Member
 
Registered: Aug 2003
Posts: 50

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by alexander_bosakov
Can you be more specific about what are you trying to do? 'echo' command sends CR by default, unless explicitly told not to do so with the '-n' option.
basicly, i just do echo "doThis"
and I expect it to jump to the next line.
 
Old 03-24-2006, 02:15 AM   #5
alexander_bosakov
Member
 
Registered: Mar 2006
Location: Plovdiv, Bulgaria
Distribution: OpenSuse 11.3
Posts: 55

Rep: Reputation: 15
Well, from your description, I suppose you are trying something like 'echo "blabla">tty_of_the_scriptB"'. Did I got it right? Anyway, if we are talking about 'bash', the 'read' operator does precisely that - reads an input, assigns it to a variable(s) and proceeds to the next line. And it can read not only from keyboard, but from any open file descriptor (see bash manpage). So if you want one script to control another, you can use a named pipe, so called FIFO (see man mkfifo) - both script open the FIFO file - one writes to it, other reads. Or you can create 2 FIFOs for bidirectional communication.
Example:

# scriptA (invoking B)
...
mkfifo fifoAtoB
mkfifo fifoBtoA
exec 16<>fifoAtoB # Open fifoAtoB at file descriptor 16 for sending commands
exec 17<>fifoBtoA # Open fifoBtoA at fd 17 for receiving responces from B
scriptB& # Run scriptB either in the background, or on another tty
# it must open the same files, one for reading "doThis", one for responding
# BTW, background process will receive SIGHUP if it try to read or write to tty
while some_condition; do
echo "$COMMAND">&16 # Send command to scriptB
read -u 17 RESPONCE # Read responce from scriptB
# process $RESPONCE
done
....
# after scriptB finishes, clean up
rm -f fifoAtoB fifoBtoA
# END scriptA --------------

##############################

# scriptB (called by A)
...
exec 17<>fifoAtoB
exec 18<>fifoBtoA
...
while some_condition; do
read -u 17 COMMAND # get command from scriptA
# do something with $COMMAND
echo "$RESPONCE">&18 # return the result. Again, do not
# try read or write to the tty from a background process
done
...
# END scriptB -----------

Last edited by alexander_bosakov; 03-24-2006 at 02:36 AM.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Have to enter WEP-key over and again artificialGekko Linux - Wireless Networking 2 11-07-2005 08:11 AM
enter wep key....where?? bariswheel Mandriva 3 12-23-2004 04:19 AM
How do you enter a Wep key? yodaf Linux - Wireless Networking 3 08-27-2004 10:59 PM
How to enter my WEP key? stuart Linux - Wireless Networking 15 07-21-2004 10:32 AM
checking for the 'enter' key Error1312 Programming 1 02-25-2004 11:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:00 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration