You are not logged in.

#1 2008-01-25 14:44:13

lovat
Member
From: Shanghai
Registered: 2008-01-03
Posts: 41

Does login shell reads ~/.bashrc file upon startup ?

A lot of books and manuals say that a login shell reads /etc/profile and ~/.bash_profile upon startup .
see:http://www.linuxfromscratch.org/blfs/vi … ofile.html

I add NAME = "tom" to ~/.bashrc ,save and exit . when I login again ,I get a login shell right ? I type echo $NAME
,then I see the output is tom. It means a login shell also reads ~/.bashrc  /etc/bashrc . Is that right ?

Last edited by lovat (2008-01-25 14:53:21)


Do not use Linux as desktop.

Offline

#2 2008-01-25 15:00:37

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,893
Website

Re: Does login shell reads ~/.bashrc file upon startup ?

yes .... if you add to .bashrc [user] it will load at boot.... or you can use source ~/.bashrc

There is a thread on bashrc on forum you may want to look at too


Mr Green

Offline

#3 2008-01-25 15:01:39

Gilneas
Member
From: Netherlands
Registered: 2006-10-22
Posts: 320

Re: Does login shell reads ~/.bashrc file upon startup ?

Try calling it with --login and without.

man bash wrote:

When  an  interactive  shell  that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists.

Generally, having your .bash_profile say source ~/.bashrc removes any confusion.

man bash wrote:

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

Offline

#4 2008-01-25 16:02:49

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: Does login shell reads ~/.bashrc file upon startup ?

It seems logical to me that .bashrc is sourced by any bash shell, .bash_profile only by login shells.

Offline

#5 2008-01-25 16:32:11

Gilneas
Member
From: Netherlands
Registered: 2006-10-22
Posts: 320

Re: Does login shell reads ~/.bashrc file upon startup ?

Ramses de Norre wrote:

It seems logical to me that .bashrc is sourced by any bash shell, .bash_profile only by login shells.

Don't forget non-interactive shells. They don't read anything by default as it should be.

Offline

#6 2008-01-26 18:07:24

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: Does login shell reads ~/.bashrc file upon startup ?

try

export NAME="tom"

instead. 'export' allows that variable to be 'exported' to the current shell and all those spawned from it.
Normally .bash_profile calls on .bashrc which normally calls on /etc/bash/bashrc which is where it gets all its important system variables plus any extras you define in it.

Offline

Board footer

Powered by FluxBB