0

I understand that ~/.zshenv gets sourced every time that an instance of zsh starts.

This implies that having the following line ~/.zshenv would result in an infinite regress:

(echo "$$ $(date)" >> $HOME/.debug.zshenv)

...because the (...) represents a subshell, and hence another sourcing of ~/.zshenv, etc.1

This reasoning notwithstanding, the line shown above is harmless, AFAICT. In particular, $HOME/.debug.zshenv shows only one line after I start a new shell with

% zsh

Clearly, ~/.zshenv is not getting sourced anew when the line above is evaluated. Why not?


1For that matter, the expression $(date) also entails creating a subshell.

2

You misunderstand the meaning of subshell. A subshell is not a completely new process but a fork of the existing process.

If you call zsh explicitly e.g.

zsh -c 'echo "$$ $(date)" >> $HOME/.debug.zshenv'

then the shell forks, calls execve() and by that starts a completely new shell which does the initialization again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.