I recently read an answer here that included the following advice:
However, as a rule, ⚠️you should not
source ~/.zshrc. Depending on what's in your dotfiles, this can lead to all sorts of problems.
I asked the OP for an example of why this could be a problem and was told:
Because it's been sourced already when your shell started up and the order in which commands are run can matter. As a simple example, put
ls() { command ls -x "$@" }; alias ls='ls -AF'into your.zshrcfile, restart your shell, thensource ~/.zshrc. Now you get an errorzsh: defining function based on alias ls'. And that's only a fairly innocuous example. Things can get much more hairy than that
That does sound plausible, although I couldn't reproduce that error with zsh. Despite its plausibility, I am having trouble imagining a situation where this could cause any serious issues and those issues would not also occur when opening a clean new session. Worst case scenario I can think of is getting an error message, and I don't even know how to make that happen either.
So, is there good reason to avoid manually sourcing a shell's rc file after making changes to it so that the changes are imported into the current shell session?
I know I have been doing this with bash for many years: I will regularly add a function, or make a change to my ~/.bashrc and then . ~/.bashrc to source it. Are there really cases where that could cause any serious problem? I suppose we can find some edge cases, but are those enough to justify such an empathetic warning? Perhaps there's something specific to zsh that I haven't encountered as a bash user?
I am interested in answers covering any bourne-family shell (bash, sh, zsh, ksh etc.).