5

I'm using Ubuntu 14.04. I used chsh to set my default shell to /usr/bin/zsh.

My ~/.zprofile defines several environment variables, e.g. export EDITOR=vim. Yet after logging in and starting GNOME Terminal, these variables are not set. After running zsh -l, they are:

% echo $EDITOR

% zsh -l
% echo $EDITOR
vim
%

So apparently when zsh is run on login it does not know it's a login shell and therefore does not read .zprofile? What gives?

As far as I can tell, this was working until recently, then suddenly it wasn't, so perhaps an upgrade broke something?

ke.
  • 167
  • 2
  • 15

1 Answers1

7

So apparently when zsh is run on login ...

You're running zsh in GNOME Terminal, not on login. Compare by switching to a TTY (CtrlAltF1), and logging in.

it does not know it's a login shell

The term "login shell" is overloaded:

  1. It's the shell mentioned in your passwd entry. Console-based login methods usually start this shell (try the TTYs, or sudo -l, or su -). "Login shell" with this context is used in discussion of user accounts.
  2. A shell can be run as a login shell, irrespective of whether it is a login shell(1) of the user. With most Bourne-like shells, that's obtained by either using -l when run manually, or by using - as the first character of argument 0 when launched indirectly (by login, sudo, su, etc.). This meaning is used while discussing invocation of shells.

So, it isn't a login shell(2), because we are discussing how it is started (invocation).


.zprofile is read by login shells (2). GNOME Terminal does not run a login shell (2) by default. You have to tell it do so:

  1. Go to Edit -> Profile Preferences.

  2. Select the Title and Command tab.

  3. Notice how the Run command as login shell checkbox is unchecked! Check it.

muru
  • 197,895
  • 55
  • 485
  • 740
  • 4
    Isn't the display manager supposed to run zsh as a login shell when I login? And aren't all my processes, including GNOME Terminal and any shell that it runs, supposed to inherit the login shell's environment so that the variables defined in the profile file are available? That seems to happen with bash and ~/.profile, but not with zsh and ~/.zprofile. – ke. Dec 12 '15 at 23:08
  • 5
    @ke. The display manager sources .profile, as it should - it's the standard, shell-independent. It does not run your login shell. The DM doesn't know (or care) that zsh uses .zprofile instead of .profile. – muru Dec 12 '15 at 23:14