13

I'm trying to set environment variable through a shell script. Here is the script with various techniques:

#!/bin/sh
echo "export SOMEPATH=/root/some" >> /root/.bash_profile
echo "export PATH=$PATH:$SOMEPATH/bin" >> /root/.bash_profile
SOMEPATH=/root/some
export SOMEPATH
source /root/.bash_profile

I run the script a.sh with sh a.sh

Then if I check the env variable it doesn't show up.

echo $SOMEPATH returns nothing. I expected to get SOMEPATH returned

merged by Michael Mrozek Nov 27 '16 at 23:00

This question was merged with How can I make environment variables “exported” in a shell script stick around? because it is an exact duplicate of that question.