I have a shell script (let's call it parent.sh) which calls another shell script (child.sh), passing it an argument.
The child script does some work and sets a value in a variable called create_sql. I want to access this create_sql variable from the parent script which invoked it.
I am calling the child script from within the parent script like this:
./child.sh "$dictionary"
and straight afterwards I have the line:
echo "The resulting create script is: "$create_sql
However, there is no value being output, however, in the child script I am doing the same thing and the variable is definitely set.
How can I get this to work so that I can read variables created by the child script?


. ./child.sh "$dictionary"(or in Bash, mimicking the C shell,source ./child.sh "$dictionary"). This reads and executes the script in the environment of the current shell, but could mess with other variables in theparent.shscript — there is no isolation between the scripts. Otherwise, a child process cannot sanely set the environment of the parent shell. (If you want to do it insanely, you can have the child shell run a debugger, attach to the parent shell process and set the environment that way — but 'insane' is polite).child.shecho the value you want in$create_sql, and then you usecreate_sql=$(./child.sh "$dictionary")with no spaces around the assignment operator.eval-ed in the parent script (likessh-agent: it will outputSSH_AUTH_SOCK=something; export SSH_AUTH_SOCK; SSH_AGENT_PID=something; export SSH_AGENT_PID;and you would use it aseval $(ssh-agent ...)in the parent)