0

I have two shell scripts.

  1. SetEnvVariable.sh
  2. 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,

enter image description here

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,

enter image description here

what I don't understand is when CONNECT_POD_RESOURCE_NAME (and later var) variable has proper value in it, how come string concatenation works fine in one case and doesn't in another case?

And what is a 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 the caller script?

2
  • 4
    Does CONNECT_POD_RESOURCE_NAME have a carriage return or some other unusual character in it? Try cat -A SetEnvVariable.sh and see what it looks like. Commented May 21, 2024 at 17:23
  • @tjm3772 Got it, the "SetEnvVariable" which was provided to me was not having linux compatible EOL character (probably built in windows I guess). I have corrected it and it is working now. Can you please put your comment properly in answer section so i can accept it as an answer. Commented May 21, 2024 at 17:45

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.