Search code examples
fish

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


I am using fish shell on a Ubuntu sytem. This question is about redundancy in $PATH that I am setting unintentionally.

When I type echo $PATH, I get:

/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 .

Multiple annoyances with this: /opt/anaconda3/bin showing up twice, showing some non-existant directories: /usr/local/games /usr/games.

My /etc/login.defs reads:

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

So the redundancy is not coming from there. Of course, my PATH in config.fish is set as:

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

My Question: where does fish get its PATH from, other than what is set in my environment and what is handed to it by: /etc/login.defs?

UPDATE: I changed to using fish_user_paths variable, per documentation which got rid of /opt/anaconda3/bin added twice. Still the /usr/games/ and /usr/local/games are getting added automagically (and those directories don't exist on my system!).


Solution

  • After looking around on the Internet, this is not a shell related issue: fish shell or any other shell. It's a Linux issue. The kernel, somewhere before forking the init, reads the: /etc/environment file and sets the system wide default path.

    In a single user environment, we could just edit that file - if we insist. Personally, I added lines to my fish profile to purge the non-existant directories from the path :

    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