I want to set my path (and some other environment variables) based on a certain directory, so I have the following file in my home directory
export MY_DIR="/path/to/dir"
export PATH=$MY_DIR/bin:$PATH
export MY_OTHER_VAR="$MY_DIR/folder"
I source that in my ~/.zshrc with the following line:
[[ -e ~/my_file.sh ]] && emulate sh -c ' source ~/my_file.sh
However, when I log in, $MY_DIR/bin
is not in my path. If I echo $PATH
, I get %F{51}~%f
where $MY_DIR/bin
should be. However, both MY_DIR and MY_OTHER_VAR were set correctly.
Have I done something wrong, or is this some weird bug in zsh (it seems to work as expected with bash)?
Edit
I have used both source
and ~
elsewhere in my zshrc
without issue. However, I tried moving the file to /etc/zsh/my_file.sh
and sourcing it from etc/zsh/zprofile
. I also tried using .
rather than source, but even with those changes, I still see the same %F{51}~%f
in my path variable. Actually, I've noticed that I see whatever my current directory is in the PATH variable, so for example, if I navigate to /etc/zsh/
and echo $PATH
, I see %F{51}/etc/zsh%f
.
Full code to reproduce:
/etc/zsh/zprofile
:
[[ -e /etc/zsh/my_file.sh ]] && emulate sh -c ' . /etc/zsh/my_file.sh'
/etc/zsh/my_file.sh
:
export MY_DIR="/home/matt/code"
export PATH="$MY_DIR/bin:$PATH"
export MY_PYTHON="$MY_DIR/python"
EDIT 2
So I am using a custom prompt which prints my current path in cyan. If I disable that prompt, my PATH variable gets set properly. In the script for the prompt, I use a variable that I call path
(lowercase). Apparently, while bash doesn't confuse it with PATH
, zsh does. Thanks to all for the help.
"
on the end of the last line) and it looks like you changed the variable names and paths in order to "anonymize" the question. This could hide the actual issue, as it might have to do with the chosen variable names or the exact way how they are used.%F{51}~%f
looks like it might be part of the prompt or some output (print -P '%F{51}~%f'
will print a cyan colored~
).sh
generally does not supportsource
(but I'm not sure aboutzsh
emulation ofsh
). Insh
, you would use.
(dot) instead. Also, I'm likewise unsure howzsh
treats the quoted tilde in this case. I would use$HOME
instead.