By default, logging in will run bash in login mode (context: Bash Startup Files). However, when I installed zsh and set it as my login shell, I found that it is not run in login mode (equivalent context: Zsh Files).
Is there any way to have Zsh run in login mode when it’s run as your login shell?
I tested this by adding a line each to /etc/profile and /etc/zprofile, to export unique environment variables. Then, I logged out and back in and tried to echo those variables. (When logging in to a graphical session, I would open QTerminal and run the echo command there.) It doesn’t matter whether I’m in a graphical session or a text-only one (accessed by hitting Ctrl-Alt-F2): in both cases, if my login shell is Bash then it’s run in login mode, but if it’s Zsh then it’s not.
I noticed the problem in the first place when I created /etc/zprofile, containing just emulate sh -c '. /etc/profile', and it didn’t work.
How did you change the login shell? Describe all steps.
Like this:
$ chsh
Password: <typed it>
Changing the login shell for <username>
Enter the new value, or press ENTER for the default
Login Shell [/usr/bin/bash]: /usr/bin/zsh
$
What is the output of grep $USER /etc/passwd
After doing the above, it’s <username>:x:1000:1000:<full name>:/home/<username>:/usr/bin/zsh
Okay, after reading your post again, I’ve discovered that while /etc/zprofile isn’t read, ~/.zprofileis! This makes absolutely no sense at first, given the documentation I linked above:
If the shell is a login shell, commands are read from /etc/zprofile and then $ZDOTDIR/.zprofile. … If ZDOTDIR is unset, HOME is used instead.
However, there is also this sentence, which I didn’t notice until now:
Files listed above as being in /etc may be in another directory, depending on the installation.
So I guess the Ubuntu zsh package is configured to use a different directory for the /etc files?
Okay, I’ve got it. My last point was correct. Running man zshon my Lubuntu machine reveals that it looks in /etc/zsh instead of /etc for its machine-wide startup files (it contains pretty much a copy-paste of the paragraph that I’ve been quoting from in this topic, but with all of the mentions of paths under /etc changed to /etc/zsh). Sure enough, when I move my /etc/zprofile to /etc/zsh/zprofile, it gets read upon login.
Moral of the story: Zsh is properly run in login mode; I was just using a flawed method of testing that.