Score:4

Duplicate system PATH variable (snap/bin:/snap/bin)

jp flag

When I run echo $PATH the duplicate output snap/bin:/snap/bin appears at the end and seems unusual.

 /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin

Is this duplication undesired? If so, how can this be changed?

Score:5
gr flag

Probably, in your ~/.bashrc or in your ~/.profile there is a command that adds /snap/bin to the $PATH without previously checking if it is still in the $PATH.

Consider that duplicated entries in $PATH variable doesn't have any impacts when you run a command that is in your $PATH. Slowdown may be present on the other hand when you run a command not in $PATH (because the command search is performed, uselessly, two or more times when duplicated entries are present), even though I think it is difficult to perceive this slowdown. Duplicate entries are also a little bit annoying when you want to visually check your $PATH variable.

If you want to avoid duplicated entries in your $PATH, you can add this command in your ~/.profile file (that is the best location for environmental variables):

# remove duplicated paths in PATH variable
PATH="$(printf "%s" "$PATH" | awk -v RS=':' '!a[$1]++ {if (NR > 1) printf RS; printf $1}')"

This command use awk to identify every item in the $PATH variable (they are separated by means of the : character) and rebuild the $PATH variable avoiding re-adding duplicated folders. It also preserves the original sort of the folders inside the $PATH variable.

You can open ~/.profile with your preferred text editor. If you open it by terminal, you don't need sudo because it belongs to your user.

XJMZX avatar
jp flag
Thank you a tonne. That makes some things a lot clearer in my mind about what's going on with environment vaiables, bash.rc and .profile - if I could ask, if .profile is the best place, then why would other commands specify ~/.bashrc ? Such as, echo "export PATH=$PATH:~/go/bin:/usr/local/go/bin" >> ~/.bashrc
Lorenz Keel avatar
gr flag
Check https://superuser.com/questions/183845/which-config-files-should-be-used-for-setting-bash-environment-variables/183956#183956 and https://superuser.com/a/183980
Lorenz Keel avatar
gr flag
If you are using zsh, maybe this link can give you some further info: https://superuser.com/a/187673
XJMZX avatar
jp flag
Thanks. That should help.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.