.bashrc not executed when opening new terminal
The code in .bashrc does not execute when I open a new terminal window in Ubuntu 12.04. I noticed this when creating a .bash_aliases file. The aliases did not show up when I opened a new terminal. However when I type
source .bashrcthe aliases did show up.
.bashrc should be run everytime I open a new terminal window right?
How do I make this happen?
@jippie No, `.profile` is read at login time, not when you open a new terminal, unless there's a misconfiguration somewhere. Selah: did you change anything from the default configuration? Please run `ps -o command $$ $PPID` in a terminal and copy-paste the output.
Might want to check `echo $SHELL`. This happened to me and the shell was /bin/sh instead of bash. Fix it in /etc/passwd and its running .bashrc.
It isn't necessarily run; at the top of the standard .bashrc is this comment:
# ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples
I believe there is an option to run bash terminal as a login shell or not. With Ubuntu, gnome-terminal does not normally run as a login shell, so .bashrc should be run directly.
For login shells (like the virtual terminals), normally the file
~/.profileis run, unless you have either
~/.bash_login, but they are not there by default. By default, Ubuntu uses only .profile.
~/.profilehas this in it:
if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi
This runs .bashrc if it is available - assuming $BASH_VERSION is present in your environment. You can check for this by entering the command
echo $BASH_VERSION, and it should display some information on version number - it should not be blank.
After understanding these instructions, I went in my terminal application I went to edit -> profile preferences -> Title and Command -> Run command as a login shell. I unchecked this. Thanks for the help.
Can you clarify when .profile (hence .bashrc) is loaded/read? It seems this is done when the users logs in to their desktop session. The answer suggests this occurs when you start a new terminal/shell session "For login shells (like the virtual terminals), normally the file ~/.profile is run... "
It is _normally_ run when you start a new login shell (not really desktop session, because you can run a new login shell from the desktop session). As I said, it is run by default, but not if you have created `~/.bash_profile` or `~/.bash_login`. You can test by checking or unchecking the checkbox in `Edit -> Profile Preferences -> Title and Command -> "Run command as a login shell`, and exit then rerun the terminal. You could echo something from .profile to test.
@Selah Your comment helped me more then the actual answer ;) thanks a lot for making the comment!
So if you have created `~/.bash_profile` or `~/.bash_login` on your system and want to keep them, but still want `~/.profile` and from there `~/.bashrc` executed, you can source it from your own `~/.bash_profile` or `~/.bash_login` with a line containing `source "$HOME/.profile"`. Gives you back the colored output of ls also in login shells!
In my case, simply the
.bashrcloader lines were missing in
# include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi
I added it manually and it worked with my fresh login
ubuntu server often does not pickup .bashrc ... above works so does ... cat .bash_profile [[ -s "$HOME/.bashrc" ]] && source "$HOME/.bashrc" # Load the default
This solved it for me! I added `pcre` and it seems like it overwrote the bash profile instead of adding it.
.bash_profileholds configuration for the bash shell. When you open a terminal, it first reads and executes commands from
~/.bash_profile. So you can add the following in
.bash_profileto setup the shell according to bashrc.
Accoding to the comment in .profile
~/.profile: executed by the command interpreter for login shells.¬ 11 This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login¬ 10 # exists
So there you go, if
~/.bash_login exists, those will get run instead of
if you want to run
~/.bashrcjust add the line
Instead of going all through that just go
Edit -> Profile Preferences -> Title and Command -> "Run a custom command instead of my shell"and in Custom command box write
bashand close it. The next time you'll open the terminal, it'll also run bash automaticlly.