where to install aliases system-wide

Asked by Luc Pi on 2013-05-30

I am making a package that contains bash aliases.

where should these aliases be installed, so that they are available system-wide?

I first put them in /etc/profile.d/my-aliases.sh

but this affects only login shells (for example it works in the consoles)
Interactive shells do not get the aliases.

environement variables are passed to interactive shells,
but aliases are not.

If I append them to /etc/bash.bashrc, this will be overwritten by a subsequant installation of bash, right?

So my question is:
Where should I install aliases, so they are available to interactive shells system-wide?

Question information

English Edit question
Ubuntu bash Edit question
No assignee Edit question
Solved by:
Luc Pi
Last query:
Last reply:
N1ck 7h0m4d4k15 (nicktux) said : #1

Aliases can be written to /etc/profile if you want system-wide applicable.


or /etc/environment

Luc Pi (oluc) said : #3

/etc/environment is for environment variables. It does not work.

/etc/profile does not work,
as explained in my question (/etc/profile is sourcing /etc/profile.d/*.sh).

N1ck 7h0m4d4k15 (nicktux) said : #4

Try to write the aliases directly to /etc/profile

This the the rule.. /etc/profile = system-wide

bashrc = user specific.


Luc Pi (oluc) said : #5

As I explained in my question, /etc/profile or /etc/profile.d/*.sh do NOT pass aliases to interactive shells.
/etc/profile = system-wide LOGIN shells
/etc/bash.bashrc = system-wide INTERACTIVE shells

/etc/bash.bashrc would be the right place for aliases, BUT it is installed by the bash package, and therefore will be overwriten by an update.

Did you try it yourself? Does it work?
If yes, could you give me idiot-proof instructions, because then I am really missing something.

Luc Pi (oluc) said : #7

Did you try it yourself?
Does it work?

N1ck 7h0m4d4k15 (nicktux) said : #8

Maybe you need something like

    shopt -s expand_aliases

Try it.

Also have you tried both ? .bashrc and /etc/profile

I didn't try this in a non-login or non-interactive shell. But at login shell yes, aliases are work just fine. Debian / Ubuntu 12.04 / Arch Linux.


Luc Pi (oluc) said : #9

expand_aliases is already 'on', by default.

> But at login shell yes, aliases are work just fine.
yes, this is what I wrote in the introduction to my question.

My question is not for login shells.
My question is for *interactive* shells.

Luc Pi (oluc) said : #11

this is about non-interactive shells

Luc Pi (oluc) said : #12

I answer to myself.

There is NO existing mechanism in ubuntu to (dpkg) install aliases system-wide.

As a workaround,
bash aliases can be installed in /etc/bash_completion.d/ which will be sourced in most cases.