LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 04-10-2020, 03:46 PM   #1
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
/etc/profile.d/ does not work in Ubuntu as in Fedora, please help set perm. alias


https://www.linuxquestions.org/quest...-a-4175442604/

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:

Code:
xxx@xxxlap:~$ d
d: command not found
xxx@xxxlap:~$ ls -laF /etc/profile.d/
total 48
drwxr-xr-x   2 root root  4096 Apr 10 16:36 ./
drwxr-xr-x 136 root root 12288 Apr 10 15:20 ../
-rw-r--r--   1 root root    96 Sep 27  2019 01-locale-fix.sh
-rw-r--r--   1 root root   825 Oct 30 08:17 apps-bin-path.sh
-rw-r--r--   1 root root   664 Apr  1  2018 bash_completion.sh
-rw-r--r--   1 root root  1003 Dec 29  2015 cedilla-portuguese.sh
-rw-r--r--   1 root root   652 Apr  3  2019 input-method-config.sh
-rw-r--r--   1 root root  1941 Jul 16  2018 vte-2.91.sh
-rw-r--r--   1 root root   954 May  2  2018 xdg_dirs_desktop_session.sh
-rwxr-xr-x   1 root root    85 Apr 10 16:36 z_local_aliases.sh*
xxx@xxxlap:~$ cat /etc/profile.d/z_local_aliases.sh 
alias d='/bin/ls -laF --color=auto'
alias dird='/bin/ls -laFp --color=auto | grep /'
closed my terminals and reopened, no luck. rebooted laptop, still no luck.

What do I need to do to get those aliases set permanently.

Thank you,
 
Old 04-10-2020, 04:52 PM   #2
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by lleb View Post
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.
 
Old 04-10-2020, 04:57 PM   #3
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Original Poster
Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
thank you for the reply

Code:
$ 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
 
Old 04-11-2020, 05:33 AM   #4
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by lleb View Post
Code:
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!

Last edited by ehartman; 04-11-2020 at 05:36 AM.
 
Old 04-11-2020, 09:23 AM   #5
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Original Poster
Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Quote:
Originally Posted by ehartman View Post
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.

Not good Ubuntu.
 
Old 05-04-2020, 08:27 PM   #6
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Original Poster
Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
ok so I attempted to duplicate this process on my desktop now running Pop!_OS, the alias works as root only, not as user. what did I goof this time?
 
Old 05-05-2020, 05:00 AM   #7
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Original Poster
Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
https://linuxize.com/post/how-to-create-bash-aliases/

found some help there. hope this helps others down the road.
 
  


Reply

Tags
alias, profile, shell, ubuntu



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Wildcard email alias in /etc/alias file custangro Linux - Enterprise 1 10-02-2009 12:17 PM
alias in /etc/profile not working samogensen Linux - Server 1 07-05-2007 08:50 PM
adding perm. alias to .bashrc Lleb_KCir Linux - General 7 12-09-2004 02:35 PM
set perm hw adress by boot homegrown Linux - Networking 1 09-11-2004 09:07 AM
find / \( -perm -0200 -o -perm -04000 \) -ls. How to remove the bit ForumKid Linux - Security 3 01-16-2002 11:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration