You are not logged in.
When I execute the command bash in my terminal, it opens a new shell which properly reads all bashrc contents. But when I run /usr/bin/bash, then it is as if $PS1 is not set and those parts in my bashrc that are supposed to used only for interactive shells are not read at all.
The weird part is running which bash gives /usr/bin/bash. So, I'm not able to figure out why running bash and /usr/bin/bash produce different results. Also, although it appears as if $PS1 is not being set (based on reading of my bashrc), the prompt is still being set.
Can anyone explain why this variation is happening?
PS: Not sure if this matters, but my bashrc is not in the default location. It is in ~/.config/bash and I've modified my /etc/bash.bashrc to source the local bashrc from the custom location.
Last edited by hashken (2015-04-15 13:19:03)
Offline
Post your .bashrc & /etc/bash.bashrc
Does the behaviour persist if you move .bashrc back to the conventional location?
What makes you think $PS1 is not being set if the prompt is correct?
Offline
Does the behaviour persist if you move .bashrc back to the conventional location?
Yeah, the behaviour persists even after moving back bashrc.
The contents of my /etc/bash.bashrc file:
#
# /etc/bash.bashrc
#
# If not running interactively, don't do anything
if [[ ! $- != *i* ]]; then
PS1='[\u@\h \W]\$ '
PS2='> '
PS3='> '
PS4='+ '
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
fi
XDG_CONFIG_HOME=$HOME/.config
XDG_CACHE_HOME=$HOME/.cache
XDG_DATA_HOME=$HOME/.local/share
if [ -f "$XDG_CONFIG_HOME/bash/bashrc" ] && [ "$0" = "bash" ]; then
. "$XDG_CONFIG_HOME/bash/bashrc"
fi
if [ -f "$XDG_DATA_HOME/bash/history" ] && [ "$0" = "bash" ]; then
HISTFILE="${XDG_DATA_HOME}/bash/history"
fi
The contents of my bashrc file:
if [ -f $XDG_CONFIG_HOME/bash/xdg ]; then
. $XDG_CONFIG_HOME/bash/xdg
fi
if [ -f $XDG_CONFIG_HOME/bash/private ]; then
. $XDG_CONFIG_HOME/bash/private
fi
####################################################################
# If not running interactively, don't do anything else
if [ -z "$PS1" ]; then
PATH=$PATH:$HOME/bin/others
return
fi
#test "$PS1" || return
####################################################################
if [ -f $XDG_CONFIG_HOME/bash/colors ]; then
. $XDG_CONFIG_HOME/bash/colors
fi
if [ -f $XDG_CONFIG_HOME/bash/general ]; then
. $XDG_CONFIG_HOME/bash/general
fi
if [ -f $XDG_CONFIG_HOME/bash/aliases ]; then
. $XDG_CONFIG_HOME/bash/aliases
fi
if [ -f $XDG_CONFIG_HOME/bash/functions ]; then
. $XDG_CONFIG_HOME/bash/functions
fi
if [ -f $XDG_CONFIG_HOME/bash/completion ]; then
. $XDG_CONFIG_HOME/bash/completion
fi
What makes you think $PS1 is not being set if the prompt is correct?
Both bash/xdg and bash/private are getting sourced. But when I run /bin/bash, the other files (colors, general, aliases etc.) are not getting sourced. Since, I'm doing a $PS1 test before sourcing these files, I concluded that $PS1 is not being set.
Offline
bashrc and history are sourced if they exist and $0 is bash:
if [ -f "$XDG_CONFIG_HOME/bash/bashrc" ] && [ "$0" = "bash" ]; then
. "$XDG_CONFIG_HOME/bash/bashrc"
fi
don't drink unwashed fruit juice.
i never make predictions, especially about the future.
Offline
That was the problem. Thanks a lot sisco31
This is the current code I'm using and everything works fine.
if [[ -f "$XDG_CONFIG_HOME/bash/bashrc" ]] && [[ "$0" =~ bash$ ]]; then
. "$XDG_CONFIG_HOME/bash/bashrc"
fi
Is there a better way than to check that end of $0 is bash?
Offline