hi,
i have a shell script which calls another shell which in turn calls another shell script.
Main_shell_script.sh
echo "In Main_shell_script.sh"
FILENAME="original.txt" # LINE 1
DST_FILENAME=$FILENAME # LINE 2
echo "FILENAME = {$FILENAME}"
echo "DST_FILENAME = {$DST_FILENAME}"
. /home/shell_script_A.sh # Calling to execute in the same address space.
DST_FILENAME=$FILENAME #LINE 3
echo "In Main_shell_script.sh"
echo "FILENAME = {$FILENAME}" # prints blank
echo "DST_FILENAME = {$DST_FILENAME}" # prints blank
shell_script_A.sh
echo "In shell_script_A.sh"
FILENAME="" # clearing the FILENAME
echo "FILENAME = {$FILENAME}
. /home/shell_script_B.sh
shell_script_B.sh
echo "In shell_script_B.sh"
FILENAME="sample.txt" # reassigning the FILENAME
echo "FILENAME = {$FILENAME}"
in the above 3 scripts,
when i am assigning a different value to variable "FILENAME" in shell_script_B.sh script, its getting assigned properly and the value of the FILENAME is "sample.txt". but when the control is returned back to the main_shell_script.sh, the value in the variable FILENAME is blank. so after assigning the FILENAME to DST_FILENAME, DST_FILENAME contains nothing.
But according to the program since i am calling each shell script with a dot (.) in front, it should run in the same address space. so the variables declared in the main shell script should be visible to the other shell script and changing the value of the variable in any shell script should reflect in the other scripts also.
but, when i change the value of FILENAME in shell_script_B.sh, the changed value is not reflected in the main_shell_script.sh.
Can anyone tell where i am going wrong??
here is the output i am getting
In Main_shell_script.sh
FILENAME = {original.txt}
DST_FILENAME = {original.txt}
In shell_script_A.sh
FILENAME = {}
In shell_script_B.sh
FILENAME = {sample.txt}
In Main_shell_script.sh
FILENAME = {}
DST_FILENAME = {}