0

I am new to shell script. I have a shell script which sources another file. Another file is just a file with name value pair. I have a confusion here.

test.dat
TEST_VARIABLE_PATH=/usr/project/workspace

script file (test_script.sh)

TEST_VARIABLE_PATH=
source test.dat
echo ${TEST_VARIABLE_PATH}

The above echo statement prints different values which makes me confused. In line 1, if I make

TEST_VARIABLE_PATH=/somepath/

, even I have sourced test.dat which has TEST_VARIABLE_PATH variable already set, echo is printing only

TEST_VARIABLE_PATH=/somepath/

where sourcing the file did not overwrite the variable.

Suppose If I have the line 1 as

TEST_VARIABLE_PATH=\`dirname $0\`/../

, source command overwrites and echo prints

TEST_VARIABLE_PATH=/usr/project/workspace

Why is this source behaving differently ? Please help me to understand.

1 Answer 1

2

It seems like you don't really source the file.

To do it properly, put the full path of the file, like :

source '/full/path/to/file'
Sign up to request clarification or add additional context in comments.

1 Comment

Or just . /path/to/file. Notice that it is dot[space]/path/to/file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.