[SOLVED] /etc/profile.d/ does not work in Ubuntu as in Fedora, please help set perm. alias
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have been following this post since it was created and marked as solved a few years back. Works fantastic for setting permanent alias's across all users.
I just attempted to do this same process in a brand new Ubuntu install with zero luck:
closed my terminals and reopened, no luck. rebooted laptop, still no luck.
Look into file /etc/profile (without .d behind it) to see if it got code like this to scan the profile.d directory:
Code:
# Append any additional sh scripts found in /etc/profile.d/:
for profile_script in /etc/profile.d/*.sh ; do
test -x $profile_script && . $profile_script
done
unset profile_script
(this is from Slackware, but to execute all .sh scripts in your distro there should be code doing something like this in your /etc/profile too).
Just search for "profile.d" in that /etc/profile script (it is the first a login bash shell executes).
PS: it is possible to do things like this for (t)csh too, but then the scripts are named *.csh and executed through the /etc/csh.login one.
$ cat /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
if [ "${PS1-}" ]; then
if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
So yes that code is there to look for *.sh scripts in /etc/profile.d
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
So yes that code is there to look for *.sh scripts in /etc/profile.d
That looks quite OK, so the problems seems to be that your terminal windows do not
execute /etc/profile.
You can test if your aliases work in a real console (ctr-alt-F2 or so), if it works there the probem is with the Terminal emulator you're using.
If probably isn't starting the shell as a LOGIN shell, so no /etc/profile nor ~/.profile are done by it.
That is one of the things I dislike about bash: the complete split between login shells and NON-login ones. From the man page:
Quote:
A login shell is one whose first character of argument zero is a -, or one started with the --login option.
An interactive shell is one started without non-option arguments and without the -c option whose standard input and error are both connected to terminals (as determined by isatty(3)), or one started with the -i option. PS1 is set and $- includes i if bash is interactive, allowing a shell script or a startup file to test this state.
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.
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists.
Note that the last case is wholly different from the first one (the login shell).
Several distributions have tried to remedy this, but this IS one of the differences between distributions:
if and how they modified this default behaviour..
You can try two things then
- find out how your terminal emulator starts the shell and let it add the --login option
- for just the profile.d files: add the above code (from /etc/profile) to your own .bashrc
Note that there is no universal (for all users) startup script for non-login shell, although a lot of distributions have changed that too:
a non-login shell could be executing /etc/bashrc first, before the user's own .bashrc
But again: that is distribution dependant!
That looks quite OK, so the problems seems to be that your terminal windows do not
execute /etc/profile.
You can test if your aliases work in a real console (ctr-alt-F2 or so), if it works there the probem is with the Terminal emulator you're using.
If probably isn't starting the shell as a LOGIN shell, so no /etc/profile nor ~/.profile are done by it.
That is one of the things I dislike about bash: the complete split between login shells and NON-login ones. From the man page:
Note that the last case is wholly different from the first one (the login shell).
Several distributions have tried to remedy this, but this IS one of the differences between distributions:
if and how they modified this default behaviour..
You can try two things then
- find out how your terminal emulator starts the shell and let it add the --login option
- for just the profile.d files: add the above code (from /etc/profile) to your own .bashrc
Note that there is no universal (for all users) startup script for non-login shell, although a lot of distributions have changed that too:
a non-login shell could be executing /etc/bashrc first, before the user's own .bashrc
But again: that is distribution dependant!
Thank you very much.
putting the if/fi code in the bashrc seemed to work.
note* One other thing I just discovered about Ubuntu I do not like, the real terminals cause the laptop to lock up. 2x tried to get to areal terminal, both with hard locks of the laptop requiring a physical power off to gain control.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.