0

I have got this shell script in init.sh

echo "hello";
export ANDROID_HOME=/home/sadaf2605/adt-bundle-linux-x86-20140702/sdk;
export PATH=${PATH}:/home/sadaf2605/adt-bundle-linux-x86-20140702/sdk/tools;
export PATH=${PATH}:/home/sadaf2605/adt-bundle-linux-x86-20140702/sdk/platform-tools
echo "end"
echo $PATH

And had this printed:

sadaf2605@sadaf-pc:~/Estimator-cordova$ ./init.sh
hello
end
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/sadaf2605/adt-bundle-linux-x86-20140702/sdk/tools:/home/sadaf2605/adt-bundle-linux-x86-20140702/sdk/platform-tools

Looks good, I know, but then immediately when I echo $Path I get nothing I did:

sadaf2605@sadaf-pc:~/Estimator-cordova$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
sadaf2605@sadaf-pc:~/Estimator-cordova$ 

Why did it not work and how can I make it work?

1 Answer 1

2

it's because when you execute it you fork a new process for it to run in, it returns to your process when it's done. To see this put an echo $$ in it to show the PID process ID.

you need to run it in your current process to do that use the source command

 $source ./your_script
Sign up to request clarification or add additional context in comments.

Comments

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.