Skip to content

Repo expects /etc/profile.d/*.sh to be sourced in interactive shells, but this is spec-breaking behaviour that appears specific to Fedora #24

Description

@Smujb

According to the bash man page:

The following paragraphs describe how bash executes its startup files.  If any of the files exist but cannot be read, bash reports an error.  Tildes are expanded in filenames as described below under Tilde Expansion in the EXPANSION section.

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists.  After reading that  file,  it  looks  for  ~/.bash_profile,  ~/.bash_login,  and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.  The --noprofile option may be used when the shell is started to inhibit this behavior.

/etc/profile.d/ is technically not in the spec, but its name clearly implies it is intended to only be sourced in /etc/profile. And sure enough, this is what Arch, Ubuntu, Debian and OpenSUSE do (though Debian has lines commented out which would allow sourcing it in bashrc with a warning that enabling it could cause issues).

Fedora however ships the following in /etc/bashrc:

...
    SHELL=/bin/bash
    # Only display echos from profile.d scripts if we are no login shell
    # and interactive - otherwise just process them to set envvars
    for i in /etc/profile.d/*.sh; do
        if [ -r "$i" ]; then
            if [ "$PS1" ]; then
                . "$i"
            else
                . "$i" >/dev/null
            fi
        fi
    done
...

This behaviour is arguably spec-breaking and out of line with other distros. This repo relies on it as /etc/profile.d/brew.sh specifically early exits if not run from an interactive shell - and from what I understand, that means the only shell in which this should execute is the TTY when logging in from there.

I am unsure what the best solution is to ensuring that interactive shells execute this code without overwriting potentially important files like /etc/bashrc - in fact I imagine this problem is why Fedora does things this way in the first place.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions