source ~/.zshrc vs exec zsh
"Reload vs. Replace — how your shell config actually takes effect"
Photo by Jake Walker on Unsplash
These both “reload” your shell config, but they work very differently under the hood.
source ~/.zshrc
This runs the file in the current shell process. No new process is created.
Your current shell’s PID stays the same
All existing variables, functions, and aliases are still in memory before the file runs
The new config is layered on top of the existing state
Stale values can persist — e.g. if you removed an export from
.zshrc, the old value is still set in your session
zsh
echo $$ # e.g. 1234
. ~/.zshrc
echo $$ # still 1234 — same processThe gotcha: it accumulates state. If PATH is appended in .zshrc, sourcing it multiple times will keep duplicating entries in PATH.
exec zsh
This replaces the current shell process with a brand new zsh instance (via the exec syscall).
Same PID is reused, but the process image is completely replaced
Starts with a clean slate — reads
.zshenv,.zprofile,.zshrcfreshNo leftover variables or stale state from the old session
Any variables that were set manually in your session (not in config files) will be gone
zsh
echo $$ # e.g. 1234
exec zsh
echo $$ # still 1234 — same PID, but brand new shell proces“Well begun is half done.”


