Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从bash脚本设置路径不会全局影响_Bash_Ubuntu_Path - Fatal编程技术网

从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