As topic states .. i have one path 3 times ( by accident ) and can not find how to remove.
Im using zsh shell for user account.
Thank You.
Im using zsh shell for user account.
Thank You.
I added only 2 lines of code rest of it - standard:Can you post your user .zshrc & global /etc/csh.cshrc
What is the shell of the user as defined in /etc/passw
neofetch
export PATH="$HOME/.local/bin/:$PATH"
What doesecho $PATH
output?
/home/evo/.local/bin/:/home/evo/.local/bin/:/home/evo/.local/bin/:/home/evo/.local/bin/:/home/evo/.local/bin/:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/evo/bin
Where exactly did you add that line? In which file? If you execute thatI added only 2 lines of code rest of it - standard:
export PATH="$HOME/.local/bin/:$PATH"
multiple times consecutively, it's going to add that /home/eve/.local/bin to the PATH each time. You then end up with multiple references to that path.Where exactly did you add that line? In which file?
but it does not remove duplicates... i want to remove duplicated paths - which now i have 6 of themuse this
assuming zsh will do posix expansionsCode:[ ${PATH%%:*} = ${HOME}/.local/bin ] || export PATH="$HOME/.local/bin:$PATH"
ZSH users
If you are a ZSH user and there are too many paths in your ~/.zshrc file, you can add the following at the end of your ~/.zshrc:
# .zshrc
typeset -U PATH
This prevents duplicates of PATH variables.
/home/evo/.local/bin:/home/evo.local/bin/:/home/evo/.local/bin:/home/evo.local/bin/:/home/evo/.local/bin:/home/evo.local/bin/:/sbin:/bin:/usr/sbin:/usr/bin/usr/local/sbin/usr/local/bin:/home/evo/bin
/home/evo/.local/bin:/home/evo.local/bin/:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/evo/bin
Commands are then read from $ZDOTDIR/.zshenv. If the shell is a login
shell, commands are read from /etc/zprofile and then $ZDOTDIR/.zpro-
file. Then, if the shell is interactive, commands are read from
/etc/zshrc and then $ZDOTDIR/.zshrc. Finally, if the shell is a login
shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.
dice@fbsd-test:~ % echo $SHELL
/bin/tcsh
dice@fbsd-test:~ % cat ~/.zshrc
export PATH="${HOME}/mypath:$PATH"
dice@fbsd-test:~ % echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/dice/bin
dice@fbsd-test:~ % zsh
fbsd-test% echo $PATH
/home/dice/mypath:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/dice/bin
fbsd-test% zsh
fbsd-test% echo $PATH
/home/dice/mypath:/home/dice/mypath:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/dice/bin
fbsd-test% zsh
fbsd-test% echo $PATH
/home/dice/mypath:/home/dice/mypath:/home/dice/mypath:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/dice/bin
Is this because i typed zsh instead of source ~/.zshrcIt sounds like you're running zsh in a zsh multiple times. Each subshell will inherit the parent's exported variables, and ~/.zshrc is invoked every time you start zsh. Thus every subshell will add a /home/evo/.local/bin to the PATH variable.
It's also possible you have that PATH line in ~/.zshrc and ~/.zprofile causing it to get executed twice.Code:Commands are then read from $ZDOTDIR/.zshenv. If the shell is a login shell, commands are read from /etc/zprofile and then $ZDOTDIR/.zpro- file. Then, if the shell is interactive, commands are read from /etc/zshrc and then $ZDOTDIR/.zshrc. Finally, if the shell is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.
Because that will spawn a subshell that inherits the parent's PATH variable and executes ~/.zshrc, adding the directory again to the existing PATH. But even if you source the file it would still get added to the existing PATH (which already included that directory).Is this because i typed zsh instead of source ~/.zshrc
dice@fbsd-test:~ % echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/dice/bin
dice@fbsd-test:~ % zsh
fbsd-test% source .zshrc
fbsd-test% echo $PATH
/home/dice/mypath:/home/dice/mypath:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/dice/bin
fbsd-test% source .zshrc
fbsd-test% echo $PATH
/home/dice/mypath:/home/dice/mypath:/home/dice/mypath:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/dice/bin
I see .. i typed zsh by accident ... .See how this works?
Code:dice@fbsd-test:~ % echo $SHELL /bin/tcsh dice@fbsd-test:~ % cat ~/.zshrc export PATH="${HOME}/mypath:$PATH" dice@fbsd-test:~ % echo $PATH /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/dice/bin dice@fbsd-test:~ % zsh fbsd-test% echo $PATH /home/dice/mypath:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/dice/bin fbsd-test% zsh fbsd-test% echo $PATH /home/dice/mypath:/home/dice/mypath:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/dice/bin fbsd-test% zsh fbsd-test% echo $PATH /home/dice/mypath:/home/dice/mypath:/home/dice/mypath:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/dice/bin
if [ -d $HOME/bin ] && ! echo $PATH | egrep -q "(^|:)$HOME/bin($|:)" ; then
export PATH=$HOME/bin:$PATH ; fi
PATH
in ~/.login_conf typeset [ {+|-}AHUaghlmrtux ] [ {+|-}EFLRZip [ n ] ]
[ + ] [ name[=value] ... ]
typeset -T [ {+|-}Uglrux ] [ {+|-}LRZp [ n ] ]
[ + | SCALAR[=value] array[=(value ...)] [ sep ] ]
typeset -f [ {+|-}TUkmtuz ] [ + ] [ name ... ]
Set or display attributes and values for shell parameters.
[...]
-U For arrays (but not for associative arrays), keep only
the first occurrence of each duplicated value. This may
also be set for tied parameters (see -T) or colon-sepa-
rated special parameters like PATH or FIGNORE, etc. Note
the flag takes effect on assignment, and the type of the
variable being assigned to is determinative; for vari-
ables with shared values it is therefore recommended to
set the flag for all interfaces, e.g. `typeset -U PATH
path'.
This flag has a different meaning when used with -f; see
below.
for dir in ~/bin ~/progs/bin; do
if [[ -z ${path[(r)$dir]} ]]; then
path=($dir $path)
fi
done
typeset -U path
path=(~/bin ~/progs/bin $path)
Code:If you are a ZSH user and there are too many paths in your ~/.zshrc file, you can add the following at the end of your ~/.zshrc: # .zshrc typeset -U PATH
typeset -U PATH
PATH="$HOME/.local/bin/:$PATH"
typeset -U path
path=(~/.local/bin/ $path)
typeset -U path
in combination with path=(~/.local/bin/ $path)
typeset -U PATH
in combination with PATH="$HOME/.local/bin/:$PATH"
path
and PATH
are tied parameters, that is: when you change one the other changes accordingly. In zsh(1), path
and PATH
are special: they are tied by default and PATH
is exported by default. export
:% typeset -U PATH
% PATH="$HOME/.local/bin/:$PATH"
% typeset -p PATH
export -UT PATH path=( /home/evo/.local/bin /sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin /home/evo/bin )
typeset -U PATH
only enforces uniqueness for PATH
. To enforce the same uniqueness behaviour for the scalar PATH
and the array path
it is recommended to use both:typeset -U path PATH
PATH="$HOME/.local/bin/:$PATH"
I found this :
Code:typeset -U PATH This prevents duplicates of PATH variables.
typeset -U
did its job and made its parts unique:so now instead of :
Rich (BB code):/home/evo/.local/bin:/home/evo.local/bin/:/home/evo/.local/bin:/home/evo.local/bin/:/home/evo/.local/bin:/home/evo.local/bin/:/sbin:/bin:/usr/sbin:/usr/bin/usr/local/sbin/usr/local/bin:/home/evo/bin
it shows me:
removed only few dupes and /home/evo/.local/bin: still is still posted twice.Rich (BB code):/home/evo/.local/bin:/home/evo.local/bin/:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/evo/bin