You are not logged in.

#1 2010-10-04 21:22:22

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

.bashrc doesn't get sourced when logging in on a tty [solved]

Subject says it all - if I log in as root from a tty rather than switching to root, root's ~/.bashrc doesn't get sourced.  What am I missing?

/root/.bashrc

if [ -f /etc/profile ]; then
    . /etc/profile
fi

if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

alias nets="netstat -nlpt"
alias nets2="lsof -i"
alias ll="ls -lh"
alias rm="rm -i"
alias mv="mv -i"
alias pp="powerpill -Syu"

# Check for an interactive session
[ -z "$PS1" ] && return

alias ls='ls --color=auto'
#PS1='[\u@\h \W]\$ '
PS1='\[\e[1;31m\][\u@\h \W]\$\[\e[0m\] '

PATH=$PATH:/root/bin

Last edited by graysky (2010-10-05 20:58:49)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2010-10-04 21:25:57

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: .bashrc doesn't get sourced when logging in on a tty [solved]

Maybe because it's your login shell, so /root/.bash_profile is sourced, rather than /root/.bashrc.

https://bbs.archlinux.org/viewtopic.php … 29#p834929

Last edited by karol (2010-10-04 21:32:27)

Offline

#3 2010-10-04 21:28:53

hbekel
Member
Registered: 2008-10-04
Posts: 311

Re: .bashrc doesn't get sourced when logging in on a tty [solved]

You're missing the INVOCATION section of man bash wink

It's common to add

. $HOME/bashrc

to your ~/.bash_profile or ~/.profile (whichever you use/choose to create) to source bashrc also for login shells.

Offline

#4 2010-10-04 21:32:32

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: .bashrc doesn't get sourced when logging in on a tty [solved]

A login shell doesn't run .bashrc but runs the .bash_profile instead (okay it's slightly more to it than that you need to read the INVOCATION section of man bash for he full story). This is normally transparent to most users as a lot of systems have a bare bones .bash_profile and instead call .bashrc from that. You need to check the profile file(s) to see whether it tries to call .bashrc - but I'm guessing it doesn't. It's /etc/profile, then  ~/.bash_profile, ~/.bash_login, and ~/.profile.

You could put the code you want into /root/.bash_profile or in /root/.bash_profile call /root/.bashrc. The .profile file is so that the same file can be sourced if using different shells.

There are also two options worth knowing about, --norc and --rcfile which change non-login interactive shell behaviour.


EDIT: waaaaayyyy too slow.

Last edited by skanky (2010-10-04 21:33:11)


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#5 2010-10-05 20:58:38

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,595
Website

Re: .bashrc doesn't get sourced when logging in on a tty [solved]

thanks for the replies, all!


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

Board footer

Powered by FluxBB