Home > OS >  Zsh not working since installing MacOS Ventura
Zsh not working since installing MacOS Ventura

Time:11-09

My .zshenv:

export ZDOTDIR=~/dotfiles
export XDG_CONFIG_HOME=~/dotfiles/.config
export MY_ENVIRONMENT="PERSONAL"

My .zshrc in ~/dotfiles:

zsh ${ZDOTDIR}/startup.sh

then startup loads in a file called .zshrc.personal where I have all of my config. If I put two statements in there:

echo "hello"
alias home="cd ~/"

and then source or restart my shell, I see the echo statement, but the alias doesn't work.

I'm guessing there's some sort of conflict with the default mac version of zsh, but I don't know how to fix it. I have no .zshrc at ~/.

I'm not in a place right now where I can reinstall the Xcode developer tools, but do we think this might solve the problem?

CodePudding user response:

This line:

zsh ${ZDOTDIR}/startup.sh

Will launch a child zsh process. That process will execute startup.sh in its environment, and then exit back to the parent.

This can be a bit easier to see with some debug printouts. $$ is the process id (pid) of the current process, and $PPID is the process id of its parent:

echo Before current:$$ parent:$PPID
zsh ${ZDOTDIR}/startup.sh
echo After current:$$ parent:$PPID

With something similar added to startup.sh, this prints:

Before current:2737 parent:2586
During current:2738 parent:2737
After current:2737 parent:2586

A child process cannot change the environment of its parent, so aliases and similar changes are effectively discarded.

One answer is to source in the script, so that the code is executed in the same environment; no child processes are involved:

. ${ZDOTDIR}/startup.sh

The debug printouts from that:

Before current:2813 parent:2586
During current:2813 parent:2586
After current:2813 parent:2586
  • Related