In order to launch a new terminal and run a zsh function on it, I am trying to run the following command from within an urxvtc terminal (the urxvtd is running as a systemd service)

     urxvtc -e zsh -c "my-zsh-defined-function"

which doesn't work as the function is unknown. I need to explicitly source my zshrc to make it work

     urxvtc -e zsh -c "source ~/.zshrc; my-zsh-defined-function"

The problem is, I don't understand why. Shouldn't zsh source .zshrc as when I run urxvtc, and then I type my-zsh-defined-function ?


It shouldn't, since you're not running zsh interactively. Quoting man zsh (section STARTUP/SHUTDOWN FILES):

[I]f the shell is interactive, commands are read from /etc/zshrc and then $ZDOTDIR/.zshrc.

You could try using -i:

-i     Force  shell to be interactive.  It is still possible to specify
       a script to execute.
  • Well, doing urxvtc -e zsh -c 'zsh -i -c my-zsh-defined-function' works fine, thanks
    – csantosb
    Dec 30 '14 at 15:14

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.