5

Most people seem to recommend using source for reloading .zshrc. Why?

First I tried out source ~/.zshrc. But it resulted in a compinit error (at reload, not for new shell instances at first .zshrc load).

My reload alias is now:

alias zsh-reload="exec zsh"

instead of:

source ~/.zshrc

The reason for this is that my previous reload method (source) triggered a compinit error;

zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]?

So I'm now doing exec because I believie it ensures the previous environment doesn't pollute the new one.

  • What are the downsides of using the exec method?
  • Is there an explicit reason for that you're doing exec or source?
  • Could exec in theory cause unexpected problems compared to the source method?
4

1 回答 1

7

使用exec,您的 shell 中的所有(未导出的)变量都将丢失,这可能不是您想要的。相反,最好通过使用compinit -i. 请参阅 zsh 手册页中的compinit段落Use of compinit

要使 compinit 静默忽略所有不安全的文件和目录,请使用选项 -i

于 2019-05-25T08:55:24.153 回答