52

I am running freshly installed Arch Linux. When I log into a user (running bash) and try to use an alias from .bashrc, it gives me the 'command not found' error. But, if I reenter bash via the 'bash' command, the command works just fine.

Yes, I am already in bash.

env initially:

SHELL=/usr/bin/bash

env after running bash, it remains:

SHELL=/usr/bin/bash

So I'm not quite sure where the problem is.

2
  • Well its actually a function: function cl(){cd $@; ls} Commented Aug 23, 2013 at 2:11
  • Possible duplicate: stackoverflow.com/a/415444/208997 Commented Aug 23, 2013 at 2:19

2 Answers 2

98

Read the INVOCATION section from "bash(1)" for full details (that's the man page for bash; use man bash). Your first shell upon logging in is a "login shell", which means that the .bashrc file is not sourced. Your second invocation creates an interactive shell, where .bashrc is sourced.

If you always want the content of your .bashrc file processed, you can add the following lines to your .bash_profile file, creating that file if it does not already exist:

if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

Per its man page, bash "[...] 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." Conventions and policies of your local system will determine which, if any, of these files already exist.

A word of caution: be aware that creating a new .bash_profile in your home directory could have the unintended side-effect of preventing the reading and executing of commands in a .bash_login or .profile file already present, changing further the behavior of subsequent logins.

Sign up to request clarification or add additional context in comments.

5 Comments

And create '~/.bash_login' file if not yet here
or use ~/.profile for any Bourne-compatible login shells. (bash)
@Qwerty: if you maintain your environment such that ~/.bash_profile and ~/.bash_login do not exist, using ~/.profile works. From a version 4.2 bash man page: "When bash is invoked as an interactive login shell, or as a non-interactive 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."
Thanks for the information guys, just started using AIX and finding it very difficult that the bashrc file is not getting loaded automatically, their is no /etc/profile, ~/.bash_profile, ~/.bash_login, ~/.profile scripts present in the machine but now created one as @jean Davy said. your answers are just to the point. Big cheers..
this answer over on unix.stackexchange has code for .bash_profile to source .bashrc and also read .profile
5

Have you looked at your ~/.profile, ~/.bash_login and ~/.bash_profile files?

1 Comment

Thanks, totally forgot about that. Not used to having to set up stuff thanks to Ubuntu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.