Hi I’ve noticed a quirk with the PATH variable. In my .bashrc file I added 2 entries (/usr/sbin & /sbin).
export PATH=$PATH:/usr/sbin:/sbin
Afterwards, when I type echo $PATH, I notice the items I added in my .bashrc appear twice. This happens for any/all additional directories I add to my PATH variable in my .bashrc Any insight into why?
First thing that happens is that $PATH is replaced by the string that is the value of PATH at that moment (this is called Parameter expansion in the man page of bash)
There is a start value of PATH and it seems to be
I have no idea why you want to add these two system directories to the PATH variable, because, as you see, they are, not surprising, already part of the default value of PATH.
My you should first think over why they are not by default in, what you call, “my” PATH.
I assume that that is the path of a “normal” user and not root, because the default PATH of root does have them. Maybe that is for a reason?
In any case, the statement you use is in fact a string expression where you add a string at the end of an existing string. When that is done again, it is added again, and again. and …
Thus it seems that for some reason you “went trough” .bashrc twice. Which is quite possible when you start a new bash from a running bash. After all the environment variables are inherited by the child process and .bashrc is added for every bash start.
.profile is only used at login to a shell and not at every start. Maybe you beter put it there.
Having them twice is of course only a minor performance loss, but having them 60 times …
Coming back to my first remark above, I have no idea why an end-user should wish to have those two libraries (that contains executables he most probably can not execute) in his PATH. But you failed to present the case. So further advice on what you should do is a bit difficult.
You are correct. When I go to a terminal (Alt + Shift + F2) and type echo $PATH I do NOT see duplicates. However, when I go to a terminal emulator (i.e. Konsole, Yakuake, etc…) and type echo $PATH I see the duplicates. So it’s something about those programs that seem to be the issue.
Seems like strange behavior indeed as I do most of my work on a terminal emulator. But thanks for pointing me in the right direction.
My preferred method of shutting down my laptop is via Konsole and typing either reboot or poweroff, which reside in /sbin. I simply type poweroff or reboot instead of /sbin/shutdown or sbin/reboot. I can probably create an alias to do the same but there may be other items in /sbin or /usr/sbin I’d like access to w/o typing the whole path. For instance accessing yast, xfs_repair, etc… via console. I’m the only user on my laptop thus it’s just a preference.