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