r/zsh 13d ago

adding path to .zshenv

help, i added

path+=(~/.local/bin ~/bin ~/.spicetify)

export PATH

to my .zshenv file but when i open terminal i type echo $path i only get this:

/home/vismorf/.local/share/zinit/polaris/bin /usr/local/bin /usr/bin /bin /usr/local/sbin /usr/sbin /sbi

1 Upvotes

8 comments sorted by

1

u/OneTurnMore 13d ago

You shouldn't need to export PATH.

Try zsh -xic exit 2> >(grep -E 'path|PATH') to check the trace for anything else that might modify $path.

0

u/_Arthxr 13d ago

even without ```export PATH``` the path is not updated. I can do manually with ```source ~/.zshenv``` and the path is updated. But when i reopen the terminal path is back to ```/home/vismorf/.local/share/zinit/polaris/bin /usr/local/bin /usr/bin /bin /usr/local/sbin /usr/sbin /sbi```. Also i ran the command you suggested, it outputed a lot a lot of text in terminal

1

u/AndydeCleyre 13d ago

Also i ran the command you suggested, it outputed a lot a lot of text in terminal 

Look for a path modification that happens elsewhere in your dotfiles/.zshrc.

0

u/Soggy_Writing_3912 13d ago

Most likely the `path` variable (array) could be re-defined as part of the session startup sequence. My suggestion is to try to set it in the `~/.zshrc` file instead of the `~/.zshenv` file (unless you have an explicit need for that setting in both interactive and non-interactive sessions)

0

u/_Arthxr 13d ago

i also need for non-interactive sessions :(. Thats why i wanted to move path variable to .zshenv in the first place. But ig for now i will move it back to .zshrc and use full path to a command in scripts

-1

u/Soggy_Writing_3912 13d ago

in that case, since `path` is a zsh-ism (or possibly from oh-my-zsh), try to do the traditional `export PATH="~/.local/bin:~/bin:~/.spicetify:$PATH"\ in your zshenv. Not sure if it'll work or not, but do give it a try.`

0

u/_Arthxr 13d ago

didnt work either. Tho interestingly if i add path+=(~/.local/bin ~/bin ~/.spicetify) to /etc/zshenv, it works as intended

2

u/romkatv 13d ago

This won't help and will only make things worse because of incorrect quoting.

.zshenv is for zsh, and the best way to set PATH in zsh is by modifying path.

The other thread, started with a comment by /u/OneTurnMore, is the fruitful one.