CachyOS has weird double entries in PATH from
~/.bash_login. Fedora checks for existing entry, but only
for PATH. So, here is generalized way of adding unique entries to
any ':' separated variable. Use it in your ~/.bash_login:
_var_string() # var
string...
{
local
-n var=$1
local
string
shift
for
string; do
[[ :$var: =~ :"$string": ]] ||
var=$var${var:+:}$string
done
}
unset -f _var_string
Usage is
_var_string PATH /i/buck/one
/tim/buck/two
export PATH
and the result is
$ declare -p
PATH
declare -x PATH="...:/i/buck/one:/tim/buck/two"
You can do similar for preprending to variable. Of course, it has
to be Bash shell, because it uses Bash features:
- name reference: local -n var
- regex match: [[ str =~ regex ]]