This question already has an answer here:
I am trying to export a variables through myDeploy.sh but the export is not getting set. When i am echoing it is not echoing. However, when i set the variable explicitly on command it sets properly and echoes too.Below is the snippet of my code.
myDeploy.sh
#!/bin/bash
# export the build root
export BUILD_ROOT=/tibco/data/GRISSOM2
export CUSTOM1=/tibco/data/GRISSOM2/DEPLOYMENT_ARTIFACTS/common/MDR_ITEM_E1/rulebase
export CLEANUP=$BUILD_ROOT/DEPLOYMENT_ARTIFACTS/common
cd $BUILD_ROOT/DEPLOYMENT_ARTIFACTS/common
When I echoes echo $BUILD_ROOT
it is not echoing the path for me. But when I do it explicitly on command prompt like
[root@krog3-rhel5-64 GRISSOM2]# export BUILD_ROOT=/tibco/data/GRISSOM2
It sets properly and echoes too. What am I missing?
Running your script like
. ./script
or
source script
would execute your script in the current shell context (without creating a subshell) and the environment variables set within the script would be available in your current shell.
From the manual: