I have a script named "als" that parses the aliases in a user's .bashrc file that I'd like to run for any user logging in via SSH.

This should display similar to a Message of the day (MOTD) banner. MOTD banners are static data though.

Here's the code.

echo Your aliases:
echo \(from ~/.bashrc\)
cat .bashrc | egrep 'alias.+\=' | tr -s [:space:] | sed 's_^ alias_alias_' | sed 's_alias__' | sort | sed 's_=_\t\t_' | sed 's_^ __'

It works if I append ./als to my ~/.profile file, but this only executes for me. Again, I'd like this to run for all users on shell login

1 Answer 1


You could save your script in /etc/profile.d/als.sh. According to Ubuntu EnvironmentVariables manual:

Files with the .sh extension in the /etc/profile.d directory get executed whenever a bash login shell is entered (e.g. when logging in from the console or over ssh), as well as by the DisplayManager when the desktop session loads.

You should also modify relative path with absolute path:

 cat /home/$USER/.bashrc | egrep 'alias.+\=' | tr -s [:space:] | sed 's_^ alias_alias_' | sed 's_alias__' | sort | sed 's_=_\t\t_' | sed 's_^ __'  

And this should works for all users.

  • This does work. Thank you. That's exactly what I was after. I was going to nail down the absolute path when I found out how to run for all shell logins.
    – user38537
    Nov 11, 2014 at 1:20
  • It worked for every logged user except root. How can I do this for the root user?
    – R. Karlus
    May 3, 2019 at 18:45
  • 1
    @Rhuan Karlus do you mean when you run commands with sudo? In this case, you shoud read "sudo caveat" paragraph in the link posted above
    – Lety
    May 4, 2019 at 16:25
  • That's exactly what I needed @Lety !! Thank you very much.
    – R. Karlus
    May 6, 2019 at 14:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .