4

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
user49888
  • 365
  • 1
  • 5
  • 13
  • 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 http://www.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? – Thorsten Staerk Sep 12 '14 at 11:15
  • 1
    That should be `.bash_profile`, not `.bash_profiles`. Was that a typo? – terdon Sep 12 '14 at 12:19
  • Related: http://unix.stackexchange.com/questions/88106/why-doesnt-my-bash-profile-work – AntonioK Sep 12 '14 at 13:56
  • @terdon Yes it's a typo, fixed. – user49888 Sep 12 '14 at 17:02
  • 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. – terdon Sep 12 '14 at 17:05
  • @ThorstenStaerk `echo $SHELL` = /bin/zsh – user49888 Sep 12 '14 at 17:13
  • @terdon See the directly above comment. That's why `~/.bashrc` isn't being run. Is there a `zsh` equivalent? – user49888 Sep 12 '14 at 17:14
  • 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 Sep 12 '14 at 17:16

1 Answers1

5

~/.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.

Jan
  • 7,600
  • 2
  • 34
  • 41
  • 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`. – terdon Sep 12 '14 at 12:15
  • @terdon Yes, that's what I meant - I'll try to reprhase it in an edit. – Jan Sep 12 '14 at 12:55
  • 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. – tripleee Jan 18 '18 at 06:07