Sunday, May 5, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 791  / 2 Years ago, sat, march 26, 2022, 5:42:09

I'm using in xubuntu bionic as shell bash.



I'll try to expand my $PATH for my user over $HOME/.profile.



if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi

if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi


The result is a little bit unexpected.



echo $PATH
/home/alex/.local/bin:/home/alex/bin:/home/alex/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games


$HOME/bin is set twice. How can I avoid it?



In $HOME/.bashrc is nothing declared.


More From » command-line

 Answers
2

I use Stephen Collyer's "Bash Path Functions" (see his article Stephen Collyer's article in Linux Journal). It permits me to use the "colon separated list" as a datatype in shell programming. For example, I can produce a list of all the directories in the current directory by:



dirs="";for i in * ; do if [ -d $i ] ; then addpath -p dirs $i; fi; done  


Then, listpath -p dirs produces a list.



Using uniqpath and listpath (from bash_path_funcs), one could simply:



walt@bat:~(0)$ PATH=$HOME/bin:$PATH
+walt@bat:~(0)$ listpath
/home/walt/bin
/home/walt/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin
/home/walt/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

+walt@bat:~(0)$ uniqpath -p PATH
+walt@bat:~(0)$ listpath
/home/walt/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/gameswalt@bat:~(0)$ PATH=$HOME/bin:$PATH

[#4973] Sunday, March 27, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eaderitable

Total Points: 368
Total Questions: 117
Total Answers: 111

Location: Tuvalu
Member since Sat, Feb 11, 2023
1 Year ago
;