环境变量 PATH 在脚本命令中发生变化

环境变量 PATH 在脚本命令中发生变化

我通常倾向于使用有用的命令来记录某些会话script。但是,我观察到,使用它时行为似乎发生了变化。确切地说,

使用之前script,python的位置如下

$ which python
/home/abhishek/Softwares/anaconda3/bin/python

而在应用时script,它会变为

$ which python
/home/abhishek/Softwares/miniconda2/bin/python

我怀疑这是由于添加到环境变量中的 Python 主目录的顺序不同,PATH我确认如下。

script

$ echo $PATH
/home/abhishek/Softwares/anaconda3/bin:/home/abhishek/Softwares/anaconda3/condabin:/home/abhishek/Softwares/miniconda2/bin:/home/abhishek/Softwares/wkhtmltox/bin:/home/abhishek/Softwares/cuda-8.0/bin:/home/abhishek/Softwares/asymptote-2.41/installation_dir/bin:/home/abhishek/bin:/home/abhishek/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/abhishek/.dotnet/tools:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin

script

$ echo $PATH
/home/abhishek/Softwares/miniconda2/bin:/home/abhishek/Softwares/wkhtmltox/bin:/home/abhishek/Softwares/cuda-8.0/bin:/home/abhishek/Softwares/anaconda3/bin:/home/abhishek/Softwares/anaconda3/condabin:/home/abhishek/Softwares/miniconda2/bin:/home/abhishek/Softwares/wkhtmltox/bin:/home/abhishek/Softwares/cuda-8.0/bin:/home/abhishek/Softwares/asymptote-2.41/installation_dir/bin:/home/abhishek/bin:/home/abhishek/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/abhishek/.dotnet/tools:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin

我尝试通过观察来理解$PATH内部是如何设置的script其中 $PATH 设置/etc/environment总的来说。从那以后,我检查了(似乎最相关的)内容

$ cat /etc/environment 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

但不确定上述变量是如何设置的机制。

因此,为了确保选择了预期的python安装,我想知道如何$PATH在内部重置script

相关内容