Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am completely new to UNIX, so pardon me if this question is incredibly stupid.

I just started an internship, where I'm given access to a build server. I want to include certain aliases by default in my environment when I log in. From what I understand, the way to do it would be to include them in a .bashrc file in my $HOME directory. But it doesn't seem to work. I read somewhere that only interactive shells and user scripts would be able to read it, is that the reason it doesn't work? I'm running Bash. So how would I go about doing this?

Thanks in advance!

share|improve this question

migrated from Jul 13 '10 at 0:23

This question came from our site for professional and enthusiast programmers.

Only interactive shells read .bashrc, but that shouldn't be an issue because you're using an interactive shell, right? What did you try so far? – David Z Jul 12 '10 at 21:57
up vote 2 down vote accepted

iman453, the files need to be named .bashrc and .bash_profile. The period before the file means it is hidden. Any idea what version of Unix or Linux the build server is running?

In my home directory I have

|-- .bash_history
|-- .bash_logout
|-- .bash_profile
|-- .bashrc
|-- .mozilla
|   |-- extensions
|   `-- plugins
|-- .ssh
|   |-- .config
|   |-- authorized_keys
|   |-- authorized_keys2
|   `-- known_hosts
|-- .viminfo
|-- .vimrc

The contents of my .bashrc file are:

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc

# User specific aliases and functions
alias chknag='sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg'
alias ducks='sudo du -cksh * | sort -n | head -50'

The contents of .bash_profile:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc

# User specific environment and startup programs


export PATH

When I SSH into this machine after I authenticate I have access to the alias ducks.

share|improve this answer
Oh, changing my bash profile to mimic yours worked! Thanks :) – iman453 Jul 13 '10 at 21:36

In your ${HOME}/.bash_profile, add the following:

# source the users bashrc if it exists
if [ -e "${HOME}/.bashrc" ] ; then
  source "${HOME}/.bashrc"
share|improve this answer

From man bash:

When bash is invoked as an interactive login shell, or as a non-inter‐ active 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 /etc/bash.bashrc and ~/.bashrc, if these files exist.

If, for example, you're logging in through a graphical user interface and then starting a terminal which is running Bash, then you're in an "interactive shell that is not a login shell".

share|improve this answer

You have to call .bashrc from your bash_profile. Refer here for Execution sequence for interactive login shell.

share|improve this answer

You must log in to answer this question.

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