Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

~/.bashrc not being applied

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
Mintsoft
Posts: 12
Joined: 2010-01-16 17:20

~/.bashrc not being applied

#1 Post by Mintsoft »

Hi Guys,

I was wondering if someone might have some ideas about why my user's bashrc is suddenly not being applied.

The actual bashrc itself works fine, it's the same as the root user's. If I sudo su then /root/.bashrc get's applied.
The only thing that happened prior to it ceasing to work was a slipup by accidently performing chmod -R g+rxs to the entire filesystem, however I can't see any reason why that would stop it being applied.

Also, if I run bash --rcfile ~/.bashrc it doesn't work either.

Any thoughts at all would be welcomed graciously!

Thanks
-Rob

smallchange
Posts: 1740
Joined: 2009-05-04 15:56
Been thanked: 1 time

Re: ~/.bashrc not being applied

#2 Post by smallchange »

If you start a bash shell as this user and then source the .bashrc file with either

Code: Select all

. ~/.bashrc
or

Code: Select all

source ~/.bashrc
does the file work?

Do you have a statement like this

Code: Select all

# Source .bashrc if it exists
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
someplace that a login shell will source, such as /etc/profile, ~/.bash_profile or ~/.profile?

milomak
Posts: 2158
Joined: 2009-06-09 22:20
Been thanked: 1 time

Re: ~/.bashrc not being applied

#3 Post by milomak »

you didn't perhaps do a change to dash?

you can check in /etc/passwd
Desktop: A320M-A PRO MAX, AMD Ryzen 5 3600, GALAX GeForce RTX™ 2060 Super EX (1-Click OC) - Sid, Win10, Arch Linux, Gentoo, Solus
Laptop: hp 250 G8 i3 11th Gen - Sid
Kodi: AMD Athlon 5150 APU w/Radeon HD 8400 - Sid

Mintsoft
Posts: 12
Joined: 2010-01-16 17:20

Re: ~/.bashrc not being applied

#4 Post by Mintsoft »

smallchange wrote:If you start a bash shell as this user and then source the .bashrc file with either

Code: Select all

. ~/.bashrc
or

Code: Select all

source ~/.bashrc
does the file work?
Yes, both of those work
smallchange wrote:Do you have a statement like this

Code: Select all

# Source .bashrc if it exists
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
someplace that a login shell will source, such as /etc/profile, ~/.bash_profile or ~/.profile?
and my ~/.profile contains:

Code: Select all

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi
milomak wrote:you didn't perhaps do a change to dash?

you can check in /etc/passwd
I'm not entirely sure what you mean, but my /etc/passwd contains:

Code: Select all

rob:x:1000:1000:Rob,,,:/home/rob:/bin/bash
if that's what you meant?

Thanks
-Rob

smallchange
Posts: 1740
Joined: 2009-05-04 15:56
Been thanked: 1 time

Re: ~/.bashrc not being applied

#5 Post by smallchange »

The /bin/bash at the end means that your shell is bash. Does a ~/.bash_profile exist? If so .profile will not be sourced. Does this happen when you login at a virtual terminal?

Mintsoft
Posts: 12
Joined: 2010-01-16 17:20

Re: ~/.bashrc not being applied

#6 Post by Mintsoft »

smallchange wrote:The /bin/bash at the end means that your shell is bash. Does a ~/.bash_profile exist? If so .profile will not be sourced. Does this happen when you login at a virtual terminal?
There's no ~/.bash_profile, and the terminal appears exactly the same logging in over ssh and physically at the machine (i.e. no bashrc).

Thanks

smallchange
Posts: 1740
Joined: 2009-05-04 15:56
Been thanked: 1 time

Re: ~/.bashrc not being applied

#7 Post by smallchange »

I was more interested in the difference between something like a gnome-terminal and a VT.

Mintsoft
Posts: 12
Joined: 2010-01-16 17:20

Re: ~/.bashrc not being applied

#8 Post by Mintsoft »

smallchange wrote:I was more interested in the difference between something like a gnome-terminal and a VT.
Oh right! Sorry, crossed wires there!

I don't have gnome installed, but both xterm and xfce-terminal don't apply the bashrc.

Something I have just noticed though, when I login I get a prompt like:

Code: Select all

-bash-3.2$
however when I run bash again (or xfce-terminal/xterm) it looks like

Code: Select all

bash-3.2$
I can't see any reason why they would differ at all o.0

Thanks
-Rob

smallchange
Posts: 1740
Joined: 2009-05-04 15:56
Been thanked: 1 time

Re: ~/.bashrc not being applied

#9 Post by smallchange »

So when you use CTL-ALT-F1 to get to a virtual terminal and login without X in the way does your .bashrc get sourced?

Mintsoft
Posts: 12
Joined: 2010-01-16 17:20

Re: ~/.bashrc not being applied

#10 Post by Mintsoft »

smallchange wrote:So when you use CTL-ALT-F1 to get to a virtual terminal and login without X in the way does your .bashrc get sourced?
Nope, not at all; this machine doesn't use a graphical login anyway.

Thanks
-Rob

User avatar
nadir
Posts: 5961
Joined: 2009-10-05 22:06
Location: away

Re: ~/.bashrc not being applied

#11 Post by nadir »

The actual bashrc itself works fine, it's the same as the root user's.
how come?

post your bashrc's.
"I am not fine with it, so there is nothing for me to do but stand aside." M.D.

Mintsoft
Posts: 12
Joined: 2010-01-16 17:20

Re: ~/.bashrc not being applied

#12 Post by Mintsoft »

nadir wrote:
The actual bashrc itself works fine, it's the same as the root user's.
how come?

post your bashrc's.
Because I replaced the root's one with this user's ages ago, however see below:
/home/rob/.bashrc

Code: Select all

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
export HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        # We have color support; assume it's compliant with Ecma-48
        # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
        # a case would tend to support setf rather than setaf.)
        color_prompt=yes
    else
        color_prompt=
    fi
fi
if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;33m\]\u@\h\[\033[00m\]:\[\033[01;33m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

#if [ -f ~/.bash_aliases ]; then
#    . ~/.bash_aliases
#fi

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    #alias grep='grep --color=auto'
    #alias fgrep='fgrep --color=auto'
    #alias egrep='egrep --color=auto'
fi

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

# disable annoying beeps
setterm -blength 0

alias mutt='mutt -f imap://rob@mail'
/root/.bashrc

Code: Select all

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
export HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        # We have color support; assume it's compliant with Ecma-48
        # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
        # a case would tend to support setf rather than setaf.)
        color_prompt=yes
    else
        color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;31m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

#if [ -f ~/.bash_aliases ]; then
#    . ~/.bash_aliases
#fi

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    #alias grep='grep --color=auto'
    #alias fgrep='fgrep --color=auto'
    #alias egrep='egrep --color=auto'
fi

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

# disable annoying beeps
setterm -blength 0

alias mutt='mutt -f imap://rob@mail'
Like I said, they're the same and it worked fine up until this weekend.

Thanks
-Rob

Mintsoft
Posts: 12
Joined: 2010-01-16 17:20

Re: ~/.bashrc not being applied

#13 Post by Mintsoft »

Solution!

I've stumbled on the solution just now, it turns out that if /bin/bash is chmod g+x then the bashrc doesn't get executed (!?), so chmod -gx /bin/bash fixed it.

Thanks for the help guys!

smallchange
Posts: 1740
Joined: 2009-05-04 15:56
Been thanked: 1 time

Re: ~/.bashrc not being applied

#14 Post by smallchange »

That must not be the entire story because my systems all have group execute on /bin/bash and my login shells hit .bash_profile which sources .bashrc.
~ $ll /bin/bash
-rwxr-xr-x 1 root root 792K Jan 2 07:26 /bin/bash

Mintsoft
Posts: 12
Joined: 2010-01-16 17:20

Re: ~/.bashrc not being applied

#15 Post by Mintsoft »

smallchange wrote:That must not be the entire story because my systems all have group execute on /bin/bash and my login shells hit .bash_profile which sources .bashrc.
~ $ll /bin/bash
-rwxr-xr-x 1 root root 792K Jan 2 07:26 /bin/bash
Sorry, typo there, I meant g+s.

Thanks

filipbeijer
Posts: 1
Joined: 2014-02-24 12:16

Re: ~/.bashrc not being applied

#16 Post by filipbeijer »

Hi,

It's because /etc/bash.bashrc seems not to be sourced in /etc/profile (at least since wheezy) as the variables tested are not in the environment. It's about $PS1 which is tested and $BASH. Both of them don't exsist at that time and the end result is that /etc/bash.bashrc is not sourced. A work around could be to add the lines below in /etc/profile just below the export PATh line at the top.

if [ "$SHELL" = "/bin/bash" ]; then
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
fi

Filip

Post Reply