Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using zsh as my default shell and using .zshrc to modify my environment variables. When I start gvim from terminal everything is fine however if I start gvim with the desktop icon, my env variables are gone. (Just to clear it out, :shell is fine but :! commands are not)

I have tried to move my environment variables to .zprofile but it didn't work. If I move them to .profile it works but then again I need to duplicate my variables as zsh does not read .profile

I don't know much about the internal handling of shells in gvim. Is it possible read .zshrc or .zprofile for :! commands?

Note: I'm using an ubuntu system. Any elegant solution involving the OS are also welcome.

share|improve this question

migrated from stackoverflow.com Aug 17 '12 at 14:19

This question came from our site for professional and enthusiast programmers.

up vote 3 down vote accepted

If it is not an interactive or a login shell I think you're left with using ~/.zshenv. The following is from section "STARTUP/SHUTDOWN FILES" in zshall(1):

Commands are then read from $ZDOTDIR/.zshenv.  If the shell is a login
shell,  commands  are  read  from  /etc/zsh/zprofile  and  then $ZDOT-
DIR/.zprofile.  Then, if the shell is interactive, commands  are  read
from  /etc/zsh/zshrc  and then $ZDOTDIR/.zshrc. Finally, if the shell
is a login shell, /etc/zsh/zlogin and $ZDOTDIR/.zlogin are read.
share|improve this answer
used .zshenv, relogged and it's working, thanks.. – gokcehan Aug 16 '12 at 20:49

using .zshrc to modify my environment variables

That's the root cause of your problem. .zshrc is a startup file for interactive shell sessions. Use it to set shell settings, not to set environment variables. Environment variables are typically set in a session file such as .profile. See Alternative to .bashrc (what goes for .bashrc also goes for .zshrc).

If zsh is your login shell, it doesn't read ~/.profile, but it reads ~/.zprofile. Note that zsh doesn't have to be your login shell even if it's your interactive shell: you can use /bin/sh as your login shell and set SHELL=$(command -v zsh) in your environment so that terminal emulators and the like run zsh. Since you say that defining your environment variables in ~/.zprofile didn't work, this is probably how your system is already set up, but it's hard to tell without information more precise that “didn't work”.

If your login shell is zsh, put the following line in your ~/.zprofile to read .profile:

emulate ksh -c '. ~/.profile'

You can usually get away with a plain . ~/.profile, because the incompatibilities between zsh and Bourne-style shells are unlikely to come up in a .profile.

share|improve this answer
well I had set my shell using chsh so I guess zsh is my login shell as well as the one showing up in $SHELL. "didn't work" meaning effects are not visible when using :! commands (I did not forget to relog as well). putting . ~/.profile alike in .zprofile doesn't solve the problem either because the problem is it does not read that file at all. Anyway Thor's answer is working, thanks.. – gokcehan Aug 16 '12 at 20:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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