从bash脚本设置路径不会全局影响
我在从bash脚本设置路径不会全局影响,bash,ubuntu,path,Bash,Ubuntu,Path,我在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
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
并将其打印出来:
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
看起来不错,我知道,但当我回显$Path时,我什么也没得到:
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$
为什么它不起作用?我怎样才能使它起作用?这是因为当你执行它时,你会为它运行一个新的进程,当它完成时,它会返回到你的进程。要查看此内容,请在其中放入echo$$以显示PID进程ID 您需要在当前进程中运行它,才能使用source命令执行此操作
$source ./your_script