I ran
git clone https://git.savannah.gnu.org/git/bash.git
cd bash/
./configure
make
./bash
I noticed that the newly launched Bash instance did not inherit the environment, specifically the PS1 variable that defines the shell prompt, from the parent shell.
The inheritance works for /bin/bash
List of sourced files is the same for /bin/bash and ./bash
./bash -lixc exit 2>&1 | sed -n 's/^+* \(source\|\.\) //p'
/bin/bash -lixc exit 2>&1 | sed -n 's/^+* \(source\|\.\) //p'
Edit:
As aviro mentiond PS1 was defined without export, so when I tried exporting it got inherited, so my initial question was wrong.
On my machine PS1 is defined in two files
/etc/bash/bashrc
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
[[ $DISPLAY ]] && shopt -s checkwinsize
PS1='[\u@\h \W]\$ '
And /etc/bash/bashrc.d/artix.bashrc
if ${use_color} ; then
if [[ ${EUID} == 0 ]] ; then
PS1='\[\033[01;31m\][\h\[\033[01;36m\] \W\[\033[01;31m\]]\$\[\033[00m\] '
else
PS1='\[\033[01;36m\][\u@\h\[\033[01;37m\] \W\[\033[01;36m\]]\$\[\033[00m\] '
fi
else
if [[ ${EUID} == 0 ]] ; then
# show root@ when we don't have colors
PS1='\u@\h \W \$ '
else
PS1='\u@\h \w \$ '
fi
fi
When I ran ./bash the PS1 is \s-\v\$ and I have no idea why.
The command listing all sourced file shows that both of these files should be sourced when run with ./bash, but for some reason they aren't or shell starts in different type/mode. Why?
PS1is not an environment variable - it's a shell variable. Those variables are not inherited from the parent. They are read from theprofile/bashrcfiles every time a new shell starts. The question is if you changed thePS1variable in the parent, or if it comes from one of yourprofile/bashrcfiles.PS1do you see, what value do you expect? Do you set the variable in a file like.bashrc? Does the problem not occur if you start/bin/bashinstead of./bash?PS1as one of the Shell Variables.export PS1=..., nowPS1will be an environment variable and childrenbashinstances will inherit it. But if you just runPS1=...(withoutexport), it will be shell variable and childrenbashprocesses won't inherit it.exported in the parent.