shell 中的 PATH 获取神秘条目(fish shell、ubuntu 系统)

PATH in shell getting mysterious entry (fish shell, ubuntu system)

我在 Ubuntu 系统上使用 fish shell。这个问题是关于我无意中设置的 $PATH 中的冗余。

当我键入 echo $PATH 时,我得到:

/opt/anaconda3/bin/ /opt/anaconda3/etc/fish/conf.d/ /opt/anaconda3/bin/ /opt/anaconda3/etc/fish/conf.d/ /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games .

对此的多重烦恼:/opt/anaconda3/bin 出现两次,显示一些不存在的目录:/usr/local/games /usr/games.

我的 /etc/login.defs 读取:

ENV_PATH        PATH=/usr/local/bin:/usr/bin:/bin

所以冗余不是来自那里。当然我的PATHconfig.fish设置为:

set -gx PATH /opt/anaconda3/bin/ (/opt/anaconda3/bin/conda info --root)/etc/fish/conf.d/ $PATH .

我的问题:fish 从哪里获得它的 PATH,而不是在我的环境中设置的以及由以下人员交给它的:/etc/login.defs?

更新:我更改为使用 fish_user_paths 变量,每个文档去掉了 /opt/anaconda3/bin 添加两次。 /usr/games/ 和 /usr/local/games 仍然会自动添加(我的系统上不存在这些目录!)。

在 Internet 上搜索后,这不是 shell 相关问题:鱼 shell 或任何其他 shell。这是一个 Linux 问题。内核在分叉 init 之前的某处读取: /etc/environment 文件并设置系统范围的默认路径。

在单用户环境中,我们可以只编辑那个文件——如果我们坚持的话。就个人而言,我在我的鱼配置文件中添加了一些行以从路径中清除不存在的目录:

if set -l index (contains -i -- /usr/local/games $PATH) set --erase PATH[$index] end if set -l index (contains -i -- /usr/games $PATH) set --erase PATH[$index] end