Ubuntu bashrc file how to find what file is used?
Asked Answered
A

3

10

How do I find which .bashrc file is loaded when shell is started? Are there any command that can tell me that?

Currently I think it is /root/.bashrc it is a Ubuntu server 10.04 LTS.

Is it userbased or?

Abreact answered 16/2, 2013 at 14:17 Comment(0)
G
13

The command you seek is man bash, which tells you:

   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  com-
   mands  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.  The --noprofile option may be  used  when  the
   shell is started to inhibit this behavior.

and

   When an interactive shell that is not a login shell  is  started,  bash
   reads  and executes commands from ~/.bashrc, if that file exists.  This
   may be inhibited by using the --norc option.  The --rcfile file  option
   will  force  bash  to  read  and  execute commands from file instead of
   ~/.bashrc.
Gabbro answered 16/2, 2013 at 14:28 Comment(0)
P
3

From here it would seem that your ~/.bashrc is run unless you are logging in as root, as /root/ is root's home.

Phidias answered 16/2, 2013 at 14:25 Comment(1)
Ok, so if I am logged in as "someuser" is it using the .bashrc in /home/someuser/.bashrc what about the .bashrc_profile?Abreact
D
3

Simply use echo. Put an expression into bashrc

echo "I am in $PWD/$0" or "I am in bashrc file".

With that you will see when logging on a printed message which will confirm you that process uses specific script file. Note - it is not wise to e.g. start a program from bashrc or bash_profile, because if program for some reason won't start or will have trouble to start, you won't be get into a shell.

Dismal answered 16/2, 2013 at 14:26 Comment(1)
Typically various files are used on startup of the shell if they exist. depending where you put your statement, you may find out that /etc/bashrc is used, /etc/bash/rcfile, /etc/profile, /etc/bash_completion.d/someother file, ~/.bashrc, ~/.profile, ~/.bash_profile etc. "root" user usually has ~/.profile while common user ~/.bash_profileDismal

© 2022 - 2024 — McMap. All rights reserved.