Setting ZSH as login shell causes various issues because it doesn't source /etc/profile

Bug #1800280 reported by Martin on 2018-10-27
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
zsh (Ubuntu)
Undecided
Unassigned

Bug Description

When setting ZSH as the default shell, /etc/profile is never sourced (because ZSH instead sources its own /etc/zsh/zprofile). That's problematic, because /etc/profile (and the files in /etc/profile.d) are responsible for a bunch of important stuff. For example:

/etc/profile.d/apps-bin-path.sh adds /var/lib/snapd/desktop to XDG_DATA_DIRS. Setting the default shell to ZSH means that desktop environments suddenly can't launch snap packages.

/etc/profile.d/input-method-config.sh works around https://bugs.launchpad.net/ubuntu/+source/gdm3/+bug/1720250, so setting the default shell to ZSH un-fixes that bug.

Arch Linux's zsh package has `emulate sh -c 'source /etc/profile'` in /etc/zsh/zprofile. Either Ubuntu's zsh package should do the same (or something similar), or Ubuntu must put important environment variable stuff somewhere else and have only bash-specific stuff in /etc/profile and /etc/profile.d.

rjc (rjcz) wrote :

> Either Ubuntu's zsh package should do the same (or something similar), or Ubuntu must put important environment variable stuff somewhere else and have only bash-specific stuff in /etc/profile and /etc/profile.d.

Whilst I sympathise with the OP - I've used ZSH as my $SHELL for a number of years in the past - I *do* object to the former - /etc/profile *must* be POSIX/Bourne shell compliant[0].

The latter - files under /etc/profile.d - *should* be POSIX/Bourne shell compliant, IMVHO.

Either way, all of the files *can* be made POSIX-compliant and have something along the lines of:

    test $SHELL = /bin/bash && {
        ...
        Bash-specific stuff here
        ...
    }

after the POSIX-only setup.

ZSH can obviously source the then-made-POSIX-compliant options from /etc/zshenv or /etc/zprofile[1] (or wherever they live nowadays).

This obviously only concerns the environment variables, settings, etc. which are required to have the same functionality in terms of the operating system, in a way which is $SHELL-agnostic. We're not talking about options which only concern Bash or Zsh users, i.e. auto-completion, etc.

[0] https://manpages.debian.org/unstable/dash/sh.1.en.html#FILES
[1] https://shreevatsa.wordpress.com/2008/03/30/zshbash-startup-files-loading-order-bashrc-zshrc-etc/

My £0.02

Hi Martin,

Martin wrote:
> When setting ZSH as the default shell, /etc/profile is never sourced

What do you exactly mean by "setting ZSH as the default shell"?

A) Using it as login shell for a specific user.
B) Letting the /bin/sh symlink point to it.

Case B is definitely not supported and explicitly discouraged by
upstream.

> /etc/profile.d/apps-bin-path.sh adds /var/lib/snapd/desktop to
> XDG_DATA_DIRS. Setting the default shell to ZSH means that desktop
> environments suddenly can't launch snap packages.

This sounds more like case B to me.

> Arch Linux's zsh package has `emulate sh -c 'source /etc/profile'` in
> /etc/zsh/zprofile. Either Ubuntu's zsh package should do the same (or
> something similar), or Ubuntu must put important environment variable
> stuff somewhere else and have only bash-specific stuff in /etc/profile
> and /etc/profile.d.

IMHO the latter needs to happen. Zsh upstream does not source
/etc/profile and users won't expect it to do that and doing it will
probably cause other user irritations and unexcpected subtle side
effects.

See https://tanguy.ortolo.eu/blog/article25/shrc for reference what
each shell loads in which case.

  Regards, Axel
--
 ,''`. | Axel Beckert <email address hidden>, https://people.debian.org/~abe/
: :' : | Debian Developer, ftp.ch.debian.org Admin
`. `' | 4096R: 2517 B724 C5F6 CA99 5329 6E61 2FF9 CD59 6126 16B5
  `- | 1024D: F067 EA27 26B9 C3FC 1486 202E C09E 1D89 9593 0EDE

> What do you exactly mean by "setting ZSH as the default shell"?

I just mean using chsh to set the default login shell. /bin/sh is left unchanged.

Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in zsh (Ubuntu):
status: New → Confirmed
tags: added: shell
tags: added: terminal
Axel Beckert (xtaran) wrote :

> > What do you exactly mean by "setting ZSH as the default shell"?
>
> I just mean using chsh to set the default login shell. /bin/sh is left unchanged.

JFTR: "default" is still the wrong term for this. There is only _one_ login shell per user. "default" always suggests that there are others to use if you don't like the default value. But there is none. The "default login shell" is still bash because that's what new users get as their login shell _by default_.

I changed the title of the bug report accordingly as it just confused me again.

summary: - Setting ZSH as the default shell causes various issues because it
- doesn't source /etc/profile
+ Setting ZSH as login shell causes various issues because it doesn't
+ source /etc/profile
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers