Score:0

What overwrites an alias created by a file in /etc/profile.d? (environment variables)

cz flag

I executed the following command to create an alias file in CentOS 7.9:

echo 'alias ll="ls -alhF --color=auto"' > /etc/profile.d/alias-ll.sh

Then once I restarted the shell, "type ll" indicated that this alias did not work. I thought this may have been due to another file in /etc/profile.d overwriting the alias, so I renamed the file to "z-alias-ll.sh". Then I restarted shell and this time, "type ll" indicated that the alias had worked successfully.

However when I do the same in Ubuntu 20.04, "type ll" indicates that it does not work. There were some filenames like "Z99-cloud-locale-test.sh" and "Z99-cloudinit-warnings.sh" in /etc/profile.d in Ubuntu, so I tried these:

echo 'alias ll="ls -alhF --color=auto"' > /etc/profile.d/Z99-alias-ll.sh
echo 'alias ll="ls -alhF --color=auto"' > /etc/profile.d/ZZ99-alias-ll.sh
echo 'alias ll="ls -alhF --color=auto"' > /etc/profile.d/Z99-z-alias-ll.sh
echo 'alias ll="ls -alhF --color=auto"' > /etc/profile.d/ZZ99-z-alias-ll.sh
echo 'alias ll="ls -alhF --color=auto"' > /etc/profile.d/Z99Zalias-ll.sh

However, when I restart the terminal, "type ll" still says, "ll is aliased to `ls -alF'".

If I make another alias file:

echo 'alias lltest="ls -alhF --color=auto"' > /etc/profile.d/alias-lltest.sh

Then after I restart the terminal, "type lltest" indicates that this file is being sourced. So, I think the alias files in /etc/profile.d are being sourced, but the alias for "ll" is being overwritten somehwere.

Since I tried prefixing with "ZZ99" etc. I don't think it's an string sorting issue, like with CentOS 7.9, where I had to add the "z-" prefix to the filename to prevent another /etc/profile.d file from taking precedence. However, I am not 100% sure.

What file, script, etc., might be taking precedence over the alias files I created in /etc/profile.d? What takes precedence over /etc/profile.d in Ubuntu, in terms of defining environment variables?

I tried on both Ubuntu 20.04 and Ubuntu 22.10, using fresh Digital Ocean droplets.

hr flag
If "the terminal" means a terminal *emulator*, such as `gnome-terminal`, then by default in Ubuntu it likely starts an *interactive non-login* shell - which reads `/etc/bash.bashrc` and `~/.bashrc` rather than the various `profile` files
Tristan avatar
cz flag
Thank you. By terminal, I meant the Digital Ocean droplet console. I did a test where I placed different aliases for the same command in /etc/bash.bashrc and /root/.bashrc, and a file in /etc/profile.d. It seems that the order of precdence is ~/.bashrc > /etc/profile.d > /etc/bash.bashrc. There was already an alias for "ll" in /root/.bashrc, that was the cause of my issue. Thank you very much for your assistance!
muru avatar
us flag
It's not a precedence, rather, whatever comes last wins. And bash does read system-wide configuration before user configuration and it does read profile before bashrc for interactive login shells.
Score:2
cn flag

Generally, user settings have precedence over system wide settings. This is also valid for aliases. User defined aliases have precedence over aliases defined at the system level. By default on Ubuntu, alias ll='ls -alF' is defined in the user's .bashrc file, thus overriding any alias you may have set elsewhere.

pierrely avatar
cn flag
and alias ls='ls -ALf' will overide the default system ls command.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.