I am running into an issue where I see command results in .zshrc being displayed twice; in trying to track down the issue I want to know how to check if .zshrc is being run (so I can tell whether it's a display issue or that .zshrc is actually ran twice).

So I am thinking some snippet that increment a counter each time .zshrc is sourced would be ideal.


Add this to your .zshrc:

echo "$(date) -- .zshrc executed" >> $HOME/.zshrc.log

You will then see a datestamp for every time the rc file is run, sourced, or otherwise executed in the file .zshrd.log in your home directory.

  • That works perfectly; and it shows me that the source is being run twice. Not sure if I should ask a separate question on how to track down why it is running twice. I checked the usual suspects mentioned here apple.stackexchange.com/questions/175362/… but don't see .zshrc being sourced anywhere else. – AnthonyC Dec 27 '16 at 19:41
  • That might indeed be worthy of a second question. But you can also add more debug output than just echo $(date) - you could also add pstree -pal to the log. You could also perhaps move the relevant scripting from .zshrc to .zsh_profile (presuming that's a thing) or modify your scripting to set an environment variable, and only run if it's not already set. – DopeGhoti Dec 27 '16 at 20:34

I ended up switching to tmux because the issue only exists when I start a new screen session. It had nothing to do with my .zshrc (tested by commenting out everything) and I removed various .profile & .zprofile etc. It was also terminal independent. I never figured out why it only happened in screen (tried to remove .screenrc etc).

  • I have the exact same situation - I moved all the zsh/bash/screen/xterm dotfiles except for my .zshrc. In my .zshrc, I have an include guard that should prevent it from executing its contents twice (including oh-my-zsh); I verified that it works. With xterm or screen, but no oh-my-zsh, it does exactly what I expect it to and there is no duplicate line. From there, in screen but not xterm, sourcing oh-my-zsh does introduce the problem! Does that give you any clues? I'm not sure what to test next. – John P Dec 17 '17 at 23:27
  • Also - I think you meant to say it was emulator-independent, since you also said it only applied to screen. – John P Dec 17 '17 at 23:31

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.