Alasdair Macintyre

Freelance Web Developer based in Manchester, UK

  • Home
  • About
  • Github
  • Facebook
  • Instagram

Bash: .bashrc, .bash_profile, bash_login and .profile in varying situations

Posted by Alasdair Macintyre on October 24, 2009
Posted in: Uncategorized. Tagged: Bash, Linux.

On login, bash runs scripts in your home directory depending on a number of factors. Note these scripts don’t seem to require being set executable. A summary, as far as I can make out (tested on Debian lenny):

/etc/profile always seems to be run first

/etc/bash.bashrc will be run next for interactive shells (aka not scripts or su -c)

If the shell has been started with the command /bin/sh, bash emulates the older sh shell and runs the ~/.profile script

A ssh login (and presumably also local login) runs ~/.bash_profile , or if it can’t be found ~/.bash_login or .profile, if they exist (~/.profile being last)

Graphical terminal emulators usually run ~/.bashrc

The command su username from a shell runs ~/.bashrc

The command su -c “command” username from a shell or script doesn’t run any of the scripts (except /etc/profile as always)

The command su -l -c “command” username runs ~/.bash_profile (the -l flag to su emulates a login shell, so the other possibilities mentioned above if .bash_profile doesn’t exist)

Posts navigation

GNU Screen: Split Screen Terminal →
  • Recent Posts

    • Snapshot backups with Btrfs and Snapper – Raspberry Pi
    • Seafile on Raspberry Pi Ubuntu 20.04
    • SSH Snippets
    • SQL Snippets
    • GNU Screen: Split Screen Terminal
  • Recent Comments

    1. Peet on Seafile on Raspberry Pi Ubuntu 20.04
    2. David Somers on GNU Screen: Split Screen Terminal
    3. Alasdair Macintyre on GNU Screen: Split Screen Terminal
    4. David Somers on GNU Screen: Split Screen Terminal
  • Archives

    • July 2020
    • June 2020
    • January 2012
    • December 2011
    • October 2009
  • Categories

    • Uncategorized
Proudly powered by WordPress Theme: Parament by Automattic.