I want to set an environment variable from a bash script that I wrote. So I created a bash script and called it set.sh. Its content is as follows:


export DEV_SRC="/home/m/mydata/sourecCode"
echo $DEV_SRC

When I run this script, the output is


But if I run this code on the same terminal that I ran the above script from,

echo $DEV_SRC

I cannot see any value, so I think the value is not exported.

Why is the value not exported?


1 Answer 1


By default bash creates a copy of the current environment, executes the script in this environment, then destroys the copy.

To execute a script in the current environment you should use this syntax:

. /home/m/mydata/sourecCode
echo $DEV_SRC


source /home/m/mydata/sourecCode
echo $DEV_SRC

Not the answer you're looking for? Browse other questions tagged or ask your own question.