You are not logged in.

#1 2018-03-16 02:45:13

magodo
Member
Registered: 2016-11-08
Posts: 18

~/.bashrc is sourced twice

Hello guys, it is strange that my $HOME/.bashrc is sourced twice whenever a virtual terminal is opened.

There is only .bashrc I'm using, no .bashrc_profile or else. I also check /etc and confirmed the only caller is bash.bashrc. I attach the content of them below:

/etc/bash.bashrc

#
# /etc/bash.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

[[ $DISPLAY ]] && shopt -s checkwinsize

PS1='[\u@\h \W]\$ '

case ${TERM} in
  xterm*|rxvt*|Eterm|aterm|kterm|gnome*)
    PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'

    ;;
  screen*)
    PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033_%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"'
    ;;
esac

[ -r /usr/share/bash-completion/bash_completion   ] && . /usr/share/bash-completion/bash_completion

# source user bashrc
[[ -f ~/.bashrc ]] && . ~/.bashrc

~/.bashrc

echo foobar

I did a test by adding

set -x

in /etc/bash.bashrc just above the line sourcing ~/.bashrc. Then open a v-terminal, i see following output:

+ [[ -f /home/magodo/.bashrc ]]
+ . /home/magodo/.bashrc
++ echo abc
abc
+ echo abc
abc
++ printf '\033]0;%s@%s:%s\007' magodo t460p '~'
[magodo@t460p ~]$ 

Looks like bash is directly calling the content of ~/.bashrc after sourcing it... I'm confused... sad

Offline

#2 2018-03-16 02:58:13

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: ~/.bashrc is sourced twice

Does this happen in a TTY? What terminal are you using, and how is it configured?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2018-03-16 02:59:08

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,543
Website

Re: ~/.bashrc is sourced twice

Simple: take that line that you added out of /etc/bash.bashrc.  Why did you add it in the first place?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2018-03-16 10:17:27

magodo
Member
Registered: 2016-11-08
Posts: 18

Re: ~/.bashrc is sourced twice

jasonwryan wrote:

Does this happen in a TTY? What terminal are you using, and how is it configured?

I'm using gnome-terminal.
It has no double echo issue if i open TTY.

Trilby wrote:

Simple: take that line that you added out of /etc/bash.bashrc.  Why did you add it in the first place?

I add the

set -x

line is only for debugging...

Offline

#5 2018-03-16 10:53:48

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,543
Website

Re: ~/.bashrc is sourced twice

I meant the line where you source ~/.bashrc.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2018-03-16 11:58:31

seth
Member
Registered: 2012-09-03
Posts: 51,473

Re: ~/.bashrc is sourced twice

@magodo, your /etc/bash.bashrc does not look like "stock" and it should not contain the "[[ -f ~/.bashrc ]] && . ~/.bashrc" line, check

pacman -Qkk bash

Offline

#7 2018-03-16 17:04:16

magodo
Member
Registered: 2016-11-08
Posts: 18

Re: ~/.bashrc is sourced twice

Hi both, thank you!

Offline

Board footer

Powered by FluxBB