Can I have different .bashrc files loading when logging into different nodes that share the same home dir?

This is, I am mostly interested to loading different PATH directories when logging as bash, depending on the different Linux nodes I log into? For example, if I log into bash in machine abc-01, I would like to have a given .bashrc loaded, but when I log into abc-02, that uses the same /home/username directory, I would like to use a different .bashrc. How can I go about doing that?


You can put things like:

if [ $HOSTNAME = "abc-01" ]; then
        sh ~/.bashrc_abc01

if [ $HOSTNAME = "abc-02" ]; then
         sh ~/.bashrc_abc02

in .bashrc and create different scripts .bashrc_abc01, .bashrc_abc02 with the actual commands. Or if there are not that many commands, you can put them in the if statements.

  • 6
    +1 or do something like . ./.bashrc-$(hostname) – glenn jackman Apr 14 '12 at 14:00
  • yes, that's shorter – lupincho Apr 14 '12 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.