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. – aviro Sep 05 '23 at 14:58PS1do 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? – Bodo Sep 05 '23 at 15:04PS1as one of the Shell Variables. – Vilinkameni Sep 05 '23 at 15:41export 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. – aviro Sep 05 '23 at 15:50exported in the parent. – Vilinkameni Sep 05 '23 at 15:54PS1is usually (and possibly in the OP's case) not exported. – Kamil Maciorowski Sep 05 '23 at 16:01./bashor/bin/bashwill make it run the commands inbashrc, but notprofilebecause it's not a login shell. – Sotto Voce Sep 05 '23 at 16:09PS1is especially odd in that Bash explicitly clears it if running non-interactively. If nothing else, that's one reason to set it inbashrc, and it might even be unconditionally set, making it rather hard to inherit the prompt from the environment. But ifbashrcdoesn't set it, and you run an interactive shell, it will get inherited as usual. That can be useful if you want to run a shell in some unusual environment and feed it a prompt to remind yourself of that. But you need to make sure your startup files support that. – ilkkachu Sep 05 '23 at 16:40PS1=inherited XYZ=inherited ./bashand see what the prompt looks like and whatecho "PS1=$PS1" "XYZ=$XYZ"print. Same for the other Bash. – ilkkachu Sep 05 '23 at 16:42/bin/bash" so the problem doesn't occur, but my initial guess was wrong, it is not related to inheritance. – Rustacean Sep 06 '23 at 17:15bash -lixdoesn't tell all files it reads. It tells the.orsourcecommands it executes. If you look at the list it outputs, it's missing/etc/profileor.profile, even though Bash does read them for a login shell. And similarly when run without the-loption, the list is missing~/.bashrc. That is, it doesn't tell the files it runs by itself, meaning it doesn't tell the options it was compiled with. – ilkkachu Sep 06 '23 at 17:37strings ./bash |grep bashrcand compare with the other binary. Or put something in/etc/bash/bashrcyou can use to tell if it was actually read, perhaps something likeecho this is /etc/bash/bashrcor whatever. Just be sure to remove it later. – ilkkachu Sep 06 '23 at 17:41