I have two shell scripts.
- SetEnvVariable.sh
- MigrationOperator.sh
In SetEnvVariable.sh
I’m setting a variable called CONNECT_POD_RESOURCE_NAME
by doing below
export CONNECT_POD_RESOURCE_NAME="connect-200"
From MigrationOperator.sh
I am calling the SetEnvVariable.sh
as below
source ./SetEnvVariable.sh
Now I have a strange observation,
If in my MigrationOperator.sh
I have a code like below,
echo $CONNECT_POD_RESOURCE_NAME
var=$CONNECT_POD_RESOURCE_NAME
echo $var
var+=",1/1,RUNNING"
echo $var
The output looks like,
This output is unexpected to me as I was expected that at last echo, $var
should have a proper concated value.
However,
if my MigrationOperator
script has the code like,
export CONNECT_POD_RESOURCE_NAME="connect-200"
echo $CONNECT_POD_RESOURCE_NAME
var=$CONNECT_POD_RESOURCE_NAME
echo $var
var+=",1/1,RUNNING"
echo $var
the output looks proper,
what I don’t understand is when, CONNECT_POD_RESOURCE_NAME
(and later var
) variable has proper value in it, how come string concate works fine in one case and doesn’t in other case?
And what is better way to set the variables in a separate script (here in this e.g. SetEnvVariable.sh
) and still be able to use it (directly and by string manipulation) in caller script?