1

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.

1 Answer 1

3

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.