You are not logged in.

#1 2016-10-18 16:33:09

mico
Member
From: Slovenia
Registered: 2004-02-08
Posts: 247

[SOLVED] Alias for all users

I am trying to set a global alias for all users. I thought to define this in either /etc/profile or better some file in /etc/profile.d/
I deliberately put some simple export before the alias definition just to be sure the file is picked up after reboot.

/etc/profile.d/ls-grep.sh

export FOO="bar"
alias abcd='ls --color=auto'

After reboot, FOO is defined but alias abcd is not defined. How can this not work?

Last edited by mico (2016-10-18 18:50:40)

Offline

#2 2016-10-18 17:52:07

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED] Alias for all users

Those files are only read by login shells. The exported variable is inherited by child processes, but the alias is not. If, for example, you or a DM only uses a login shell to start an X server and you run an interactive shell in a terminal emulator, that shell does not read /etc/profile(.d/*) but it will inherit $FOO.

You can add aliases in /etc/skel/.bashrc to enable them for new users. If you want to add aliases later for existing users, you can loop over the users and append to their ~/.bashrc or make them source some global list of aliases in their ~/.bashrc. I'm not aware of any standard (global) file location that is automatically sourced.

Offline

#3 2016-10-18 18:00:01

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,645

Re: [SOLVED] Alias for all users

Raynman wrote:

I'm not aware of any standard (global) file location that is automatically sourced.

https://wiki.archlinux.org/index.php/Ba … tion_files

I put an alias in /etc/bash.bashrc and it is available to all my users (in an interactive shell.)

Offline

#4 2016-10-18 18:25:22

mico
Member
From: Slovenia
Registered: 2004-02-08
Posts: 247

Re: [SOLVED] Alias for all users

Cheers, that explains it.
I will probably use /etc/bash.bashrc.

Offline

#5 2016-10-18 19:02:50

S3NTYN3L
Member
From: Blito-P3
Registered: 2015-07-29
Posts: 43

Re: [SOLVED] Alias for all users

Define your alias in /etc/bash.bashrc

alias foo='bar'

Go to EOF of /etc/profile and add:

source /etc/bash.bashrc

Then, back at the prompt, simply:

source /etc/bash.bashrc

EDIT: My bad, it seems that /etc/profile already sources /etc/bash.bashrc.
Although, in my defense, I have seen versions of /etc/profile that did not.

Last edited by S3NTYN3L (2016-10-18 19:21:37)

Offline

Board footer

Powered by FluxBB