Passing a variable from a child script back to the parent

Hi

I have written a script using ftp to get files from one server and copy them to 2 dirrerent servers. I wish to call this script from a parent script that will check the number of files copied and run a check sum for each file. As the filenames for the files in the get portion of the script are hard coded into the child script is it possible to pass these files names from the child back to the parent. I have seen some error checking examples but no examples of variable being passed back.

Any help would be greatly appreciated.

You can find an example here:

Regards

Andy, If you use ksh93 this will work.

Stick your child scripts into functions - or at least have functions which run the child scripts using the . operator so that they are running within the same process as the main script.

then do something like below:
------------------------------------------

function afunc
{
# This is the function which either contains the child script or calls it using # the . operator

# the line below makes parameter 1 a by reference parameter
typeset -n pFilename=$1
..
..
.. script sets vValue to a filename received by FTP somewhere in here
.. for example vValue="receivedfile.txt"
pFilename=$vValue

return 0
}

# The main script is here
..
..
..
# lets call the function
afunc vFilename
# note that vFilename = $1 in afunc and will point to the same memory address as pFilename variable in the function
echo $vFilename
# which miraculously will turn out to be "receivedfile.txt"
-------------------------------------------------------------

You could do something similar with ksh bash or sh but that would work because all the variables of scripts using the same process are global - some versions of bash may have ksh93 features though.

If you must use scripts which don't use the same processes then the following will work:

#---- Calling script--------
..
..
# call the child script
childscript.sh
avar=`cat afile`
echo $avar
..
..
#---end of calling script-------------------

#---childscript.sh---------------
..
.. bvar="receivedfile.txt" happens somewhere in here
..
echo $bvar > afile
#------ end of childscript.sh

Another way is to use a named pipe to communicate between the 2 scripts. Do a Web search for "shell named pipe".