packages icon indicating copy to clipboard operation
packages copied to clipboard

Bash does not inherit PATH from parent process (T10037)

Open celticmagic opened this issue 2 years ago • 4 comments

Enrico Lusiani (#elusian), 2021-11-25 10:42:01 UTC

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

celticmagic avatar Aug 16 '23 16:08 celticmagic

Fabio (#livingsilver94), 2021-11-25 11:00:19 UTC

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

celticmagic avatar Aug 16 '23 16:08 celticmagic

Reilly Brogan (#ReillyBrogan), 2022-02-22 06:37:26 UTC

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.

celticmagic avatar Aug 16 '23 16:08 celticmagic

Beatrice T. Meyers (#DataDrake), 2022-03-13 00:23:40 UTC

#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.

celticmagic avatar Aug 16 '23 16:08 celticmagic

@ReillyBrogan was there any path forward on this?

Justinzobel avatar Feb 10 '24 07:02 Justinzobel

The fix had to be reverted: https://github.com/getsolus/packages/commit/625778085ad79af84209375b02a4d12904046e1b

PATH was seemingly never being set. /usr/local/bin:/usr/bin:/bin appears to be set before 10-path.sh is sourced resulting in no changes to PATH ever occuring and /usr/sbin not being in PATH.

HarveyDevel avatar Jun 25 '24 13:06 HarveyDevel

I have put up https://github.com/getsolus/packages/pull/3096 for testing and for inspiration.

It's possible that the sane thing to do here is to set the very basic paths up in a systemd environment file, and then do logic for each officially supported* shell that takes into account existing PATH contents when updating the PATH (which is what the PR above does for bash).

*: I don't think we actually have any policy on which shells we officially support?

ermo avatar Jun 26 '24 13:06 ermo