脚本命令中的环境变量PATH更改

I usually tend to keep a log of certain sessions using the useful script command. But, I observed that behaviour seems to change upon using it. To be precise,

before using script, the location of python is given as follows

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

while upon applying script, it changes to

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

I suspected this was due to different order of Python home directories being added to env variable, PATH which I confirmed as below

before 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

after 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

I tried understanding how $PATH is set inside script by looking at where $PATH is set in general. From that, I checked the contents of /etc/environment (which seemed most relevant) as

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

虽然不确定如何从上方设置变量的机制。

Hence, to ensure intended python installation is chosen, I would like to know how $PATH is reset inside script

评论