Bash default /etc/bash.bashrc overwrites PS1 even if SUDO_PS1 is set

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Bash default /etc/bash.bashrc overwrites PS1 even if SUDO_PS1 is set

Eric Engstrom
Dear Bash Maintainer(s),

Bash's default /etc/bash.bashrc (on debian systems at least) blindly
overwrites PS1 even if it's been set already.  This makes it difficult
to use sudo's abiltity to set PS1 via the SUDO_PS1 env var.

Perhaps overly simplistic, but the following modification seems to work
in all the situations I've tried:

    --- /etc/bash.bashrc.orig       2014-11-12 17:08:49.000000000 -0600
    +++ /etc/bash.bashrc    2015-06-24 12:13:36.445096411 -0500
    @@ -16,7 +16,10 @@
     fi

     # set a fancy prompt (non-color, overwrite the one in /etc/profile)
    -PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    +# but only if not SUDOing and have SUDO_PS1 set; then assume smart
user.
    +if ! [ -n "${SUDO_USER}" -a -n "${SUDO_PS1}" ]; then
    +  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    +fi

     # Commented out, don't overwrite xterm -T "title" -n "icontitle" by
default.
     # If this is an xterm set the title to user@host:dir

Thanks,
Eric
--
Eric Engstrom - [hidden email] - PGP Key: 0xC440235DF11F74CF
$/='O'; eval ($_='print $_^pack"c25",<DATA>');
__END__
58O7O26O26O84O65O74O48O42O24O4O17O75O114O6O64O89O2O68O93O39O42O49O51O52

Reply | Threaded
Open this post in threaded view
|

Re: Bash default /etc/bash.bashrc overwrites PS1 even if SUDO_PS1 is set

DJ Mills
On Mon, Dec 18, 2017 at 11:25 AM, Eric Engstrom <[hidden email]> wrote:

> Dear Bash Maintainer(s),
>
> Bash's default /etc/bash.bashrc (on debian systems at least) blindly
> overwrites PS1 even if it's been set already.  This makes it difficult
> to use sudo's abiltity to set PS1 via the SUDO_PS1 env var.
>
> Perhaps overly simplistic, but the following modification seems to work
> in all the situations I've tried:
>
>     --- /etc/bash.bashrc.orig       2014-11-12 17:08:49.000000000 -0600
>     +++ /etc/bash.bashrc    2015-06-24 12:13:36.445096411 -0500
>     @@ -16,7 +16,10 @@
>      fi
>
>      # set a fancy prompt (non-color, overwrite the one in /etc/profile)
>     -PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
>     +# but only if not SUDOing and have SUDO_PS1 set; then assume smart
> user.
>     +if ! [ -n "${SUDO_USER}" -a -n "${SUDO_PS1}" ]; then
>     +  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
>     +fi
>
>      # Commented out, don't overwrite xterm -T "title" -n "icontitle" by
> default.
>      # If this is an xterm set the title to user@host:dir
>
> Thanks,
> Eric
> --
> Eric Engstrom - [hidden email] - PGP Key: 0xC440235DF11F74CF
> $/='O'; eval ($_='print $_^pack"c25",<DATA>');
> __END__
> 58O7O26O26O84O65O74O48O42O24O4O17O75O114O6O64O89O2O68O93O39O42O49O51O52
>

I think you'll find that the string "bash.bashrc" doesn't exist in any bash
documentation. It's a thing that's
been added by your OS/distro. You need to talk to the Debian maintainer.
Reply | Threaded
Open this post in threaded view
|

Re: Bash default /etc/bash.bashrc overwrites PS1 even if SUDO_PS1 is set

Eric Engstrom
doh - thanks - didn't think of that, and that makes more sense.

Nevermind then.

On 12/18/17 1:11 PM, DJ Mills wrote:

>
>
> On Mon, Dec 18, 2017 at 11:25 AM, Eric Engstrom <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Dear Bash Maintainer(s),
>
>     Bash's default /etc/bash.bashrc (on debian systems at least) blindly
>     overwrites PS1 even if it's been set already.  This makes it difficult
>     to use sudo's abiltity to set PS1 via the SUDO_PS1 env var.
>
>     Perhaps overly simplistic, but the following modification seems to work
>     in all the situations I've tried:
>
>         --- /etc/bash.bashrc.orig       2014-11-12 17:08:49.000000000 -0600
>         +++ /etc/bash.bashrc    2015-06-24 12:13:36.445096411 -0500
>         @@ -16,7 +16,10 @@
>          fi
>
>          # set a fancy prompt (non-color, overwrite the one in /etc/profile)
>         -PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
>         +# but only if not SUDOing and have SUDO_PS1 set; then assume smart
>     user.
>         +if ! [ -n "${SUDO_USER}" -a -n "${SUDO_PS1}" ]; then
>         +  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
>         +fi
>
>          # Commented out, don't overwrite xterm -T "title" -n "icontitle" by
>     default.
>          # If this is an xterm set the title to user@host:dir
>
>     Thanks,
>     Eric
>     --
>     Eric Engstrom - [hidden email] <mailto:[hidden email]> - PGP
>     Key: 0xC440235DF11F74CF
>     $/='O'; eval ($_='print $_^pack"c25",<DATA>');
>     __END__
>     58O7O26O26O84O65O74O48O42O24O4O17O75O114O6O64O89O2O68O93O39O42O49O51O52
>
>
> I think you'll find that the string "bash.bashrc" doesn't exist in any
> bash documentation. It's a thing that's
> been added by your OS/distro. You need to talk to the Debian maintainer.
>

--
Eric Engstrom - [hidden email] - PGP Key: 0xC440235DF11F74CF
$/='O'; eval ($_='print $_^pack"c25",<DATA>');
__END__
58O7O26O26O84O65O74O48O42O24O4O17O75O114O6O64O89O2O68O93O39O42O49O51O52

Reply | Threaded
Open this post in threaded view
|

Re: Bash default /etc/bash.bashrc overwrites PS1 even if SUDO_PS1 is set

Bob Proulx
Eric Engstrom wrote:
> doh - thanks - didn't think of that, and that makes more sense.
>
> Nevermind then.

In the /usr/share/doc/bash/README.Debian.gz file:

5. What is /etc/bash.bashrc? It doesn't seem to be documented.

   The Debian version of bash is compiled with a special option
   (-DSYS_BASHRC) that makes bash read /etc/bash.bashrc before ~/.bashrc
   for interactive non-login shells. So, on Debian systems,
   /etc/bash.bashrc is to ~/.bashrc as /etc/profile is to
   ~/.bash_profile.

Bob