.bashrc and .bash_profile not executed

11,867

~/.bashrc is only executed for non-login shells, check your terminal settings:
Edit -> Profile Preferences -> Title and Command -> "Run command as a login shell

The usual ~/.profile loads ~/.bashrc if it is available, if - assuming $BASH_VERSION is present in your environment.

Keep in mind though that ~/.profile is ignored if if there's ~/.bash_profile or ~/.bash_login in your home and that, as a result of it being ignored, ~/.bashrc isn't sourced, too.

Share:
11,867

Related videos on Youtube

user49888
Author by

user49888

Updated on September 18, 2022

Comments

  • user49888
    user49888 almost 2 years

    I'm running RHEL5. I added simple alias command into ~/.bashrc. When I start a new terminal, nothing happens but source ~/.bashrc works so I know the syntax is correct. I also modified/source-tested ~/.bash_profile but it's not executed on terminal startup either. ~/.bash_login and ~/.profile don't exist on my system.

    here is my ~/.bashrc

    # .bashrc
    
    # Source global definitions if [ -f /etc/bashrc ]; then
            . /etc/bashrc fi
    
    # User specific aliases and functions
    alias hi=hello
    

    And my ~/.bash_profile

    # .bash_profile
    
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
            . ~/.bashrc
    fi
    
    # User specific environment and startup programs
    
    PATH=$PATH:$HOME/bin
    
    export PATH
    
    • Thorsten Staerk
      Thorsten Staerk almost 10 years
      How do you start a new terminal? If you start it by clicking onto an icon this should be okay as this will start a non-login shell. Are you sure you are inside a bash shell? Type echo $SHELL, the system's response should be /bin/bash. On linuxintro.org/wiki/Boot_process#user_starts_a_shell I describe that the process sourcing .bashrc is login. Can you just call bash and see if .bashrc is being executed?
    • terdon
      terdon almost 10 years
      That should be .bash_profile, not .bash_profiles. Was that a typo?
    • Doug
      Doug almost 10 years
    • user49888
      user49888 almost 10 years
      @terdon Yes it's a typo, fixed.
    • terdon
      terdon almost 10 years
      Thanks. Now, please confirm that 1) you're running bash and not another shell and 2) your terminal is not configured to start login shells. If neither .bashrc nor .bash_profile is being sourced, you're likely not running bash at all.
    • user49888
      user49888 almost 10 years
      @ThorstenStaerk echo $SHELL = /bin/zsh
    • user49888
      user49888 almost 10 years
      @terdon See the directly above comment. That's why ~/.bashrc isn't being run. Is there a zsh equivalent?
    • terdon
      terdon almost 10 years
      Yes, it's ~/.zshrc. In that case, I am closing your question as non-reproducible since it is unlikely to help future visitors. If you have a new zsh question, feel free to ask it.
  • terdon
    terdon almost 10 years
    You're probably right about the OP starting login shells but note that the "usual" .profile does not source .bashrc. It does on some systems but it is not the case everywhere and is not true on the SuSe system I just checked. Your last line is wrong, .profile itself is ignored if either .bash_profile or .bash_login exist, this has nothing to do with whether or not .bashrc is read by .profile.
  • Jan
    Jan almost 10 years
    @terdon Yes, that's what I meant - I'll try to reprhase it in an edit.
  • tripleee
    tripleee over 6 years
    In recent-ish Debian default files, .profile checks if it's running Bash, and if so, loads .bashrc. In the glacial terms of Debian development, this is a relatively recent arrangement, and certainly not generalizable to other distributions. Perhaps Red Hat had this for a longer time.