Page MenuHomeSolus

Bash does not inherit PATH from parent process
Open, Needs More InfoPublic

Description

I'm not sure if this counts as a bug, but it was for sure an unexpected behaviour.

Due to the configuration in the default bashrc, currently the PATH is reset every time bash starts.
For example if I do

export PATH=/stuff:$PATH
bash
echo $PATH

PATH will not contain /stuff anymore.
This is caused by the file in /usr/share/defaults/etc/profile.d/10-path.sh, which is sourced at the start of bashrc.

As far as I could tell this behaviour has been like this since the first commits in bash and baselayout (where I believe the default bashrc resides), so I can't find a real motivation for why Solus does this.

I would expect the PATH variable to behave like the rest of the environment and propagate to the child processes.

I'm not sure how other distros do it (I verified it works in Ubuntu and Manjaro), possibly they reset the PATH only on login shells

Event Timeline

Fedora also retains $PATH in subshells. Just confirming it's a common behavior among distros.

I _think_ this is a @DataDrake issue, because the last time I saw discussion about how profile.d should work (back when we had the GVFS/Hexchat issue) she had strong opinions on the topic.

I'm unsure if the solution is to modify the 10-path.sh script to only try to set an initial path if the PATH variable is unset (at which point any other profile.d script that appends to the path needs to be updated as well to be smarter about that) or subshells shouldn't be sourcing profile.d in the first place.

DataDrake triaged this task as Needs More Info priority.Mar 13 2022, 12:23 AM
DataDrake moved this task from Backlog to System and Configuration Fixes on the Software board.

@ReillyBrogan I'd need to see a little more testing related to this. What does PATH look like after a reboot without 10-path.sh at all, for example.

In general, I agree that subshells should inherit an existing PATH the initial PATH should only contain things we want. I'm just not sure how best to go about this.