help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: who sets my PATH when calling env -i bash --norc --noprofile?


From: Greg Wooledge
Subject: Re: who sets my PATH when calling env -i bash --norc --noprofile?
Date: Sat, 8 Apr 2023 20:01:33 -0400

On Sun, Apr 09, 2023 at 01:55:18AM +0200, Philippe Cerfon wrote:
> (2) interestingly:
> $ env -i bash --norc --noprofile -c "echo $PATH"
> /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

Let's address that one first.  You've expanded $PATH inside double
quotes, which means its value is coming from your current interactive
shell.  It's not coming from the child bash process at all.

> By coincidence I've stumbled over the following on a Debian system:
> 
> (1) From bash I run:
> $ env -i bash --norc --noprofile
> bash-5.2$ echo $PATH
> /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.

Must be post-stable Debian.  Here's what I have:

unicorn:~$ env -i bash --norc --noprofile
bash-5.1$ echo "$PATH"
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.

> I'm a bit concerned that the former contains "." but I cannot even
> find out who sets the PATH.

unicorn:~$ strings /bin/bash | grep -F usr/local/sbin
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.

Looks like it's compiled into bash.

Looking at the source tree:

unicorn:/var/tmp/bash/bash-5.2$ grep -r -F usr/local/sbin .
./config-top.h:  
"/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:."
./doc/bash.html:<TT>/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin</TT>.
[...]

Looking at config-top.h:

/* The default value of the PATH variable. */
#ifndef DEFAULT_PATH_VALUE
#define DEFAULT_PATH_VALUE \
  "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:."
#endif

Seems to be the same value that we're seeing on Debian, meaning that
Debian isn't changing this default.  It comes from upstream bash.

One could make a really good case for removing the :. from the end of
that default PATH.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]