LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   send automatic input to a script called by another script in bash programming (http://www.linuxquestions.org/questions/programming-9/send-automatic-input-to-a-script-called-by-another-script-in-bash-programming-164502/)

jorgecab 03-31-2004 07:14 AM

send automatic input to a script called by another script in bash programming
 
Hi, I am working on a bash script in which I have to call another script that prompts for data from the user, the problem is that the data that it prompts I want to fill it automatically so the user only have to run my script and fill the data from the script I call from my own script. I used to do that with the expect library but I donṫ want to use it on this one and use only bash programming.

Does anybody knows how to send this data to the other script from the parent script? I hope I made myself clear...

Thanks for the help!!!

Jorge

Hko 03-31-2004 09:33 AM

Code:

#!/bin/bash
echo "This is the input" | the_other_script.sh


rnturn 04-01-2004 12:20 AM

Re: send automatic input to a script called by another script in bash programming
 
Quote:

I am working on a bash script in which I have to call another script that prompts for data from the user, the problem is that the data that it prompts I want to fill it automatically so the user only have to run my script and fill the data from the script I call from my own script.
Normally, when script A runs script B, it starts a new process to run that script. Script B inherits environment variables from script A. Any variables defined by script B are defined in its environment and they are lost when that script terminates. So script A doesn't know about the variables modified during B's run.

Except... if you don't spawn that new process. If you run script B in the same process, you can see B's variables. Try the following
Code:

#!/bin/bash
# Script A
echo "A: Running"
REPLY=undefined
. ./B
echo "A: Your reply was: ${REPLY}"

and
Code:

#!/bin/bash
# Script B
echo "B: What is your reply?"
read REPLY

(I sure hope that doesn't get garbled; there's pound signs and braces in those code blocks.) I think it'll do what you want. The thing that makes it work is the ". " (note the trailing space) before the script you're running. Of course, you'll have all those "reserved" environment variables that you have to watch out for if you invoke all your scripts this way. It'd be like dealing with BASIC variables or defining all your program variables in FORTRAN unnamed COMMON (uh oh, I'm dating myself :-) )

Anyway, hope this helped.

Good luck,
Rick


All times are GMT -5. The time now is 09:21 AM.