FS#50794 - [bash] /etc/bash.bashrc clobbers PS{1,2,3,4}

Attached to Project: Arch Linux
Opened by Alain Kalker (ackalker) - Friday, 16 September 2016, 04:23 GMT
Last edited by Bartłomiej Piotrowski (Barthalion) - Wednesday, 09 November 2016, 20:15 GMT
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Bartłomiej Piotrowski (Barthalion)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:

I sometimes want to debug trace (with line number info, etc.) a shell script without editing it, which is why I would want to do:

$ export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
$ bash -x somescript

This doesn't work as expected: trace output is in default format. It turns out that PS4 gets set to default value of '+ ' even when I exported it with a different value.

It appears that /etc/bash.bashrc (sourced by /etc/profile when shell is bash) sets PS{1,2,3,4} to hardcoded defaults for interactive shells.

I don't know the rationale behind the change which added this[1] back in 2009, but it seems to me rather rude and superfluous at best, as bash sets these prompt variables (at least PS{1,2,4} for interactive shells anyway when they have no values . See the function `initialize_shell_variables` in `variables.c`, in particular the calls to `set_if_not()`.

If there is some compelling reason to set these variables in /etc/bash.bashrc, please at least do so only if they don't already have values.

[1]: https://git.archlinux.org/svntogit/packages.git/commit/trunk?h=packages/bash&id=c2cd913b6581e10c2c3f68d312f13a27c404a09e

Additional info:
* package version(s)
bash 4.3.046-1
* config and/or log files etc.


Steps to reproduce:
This task depends upon

Closed by  Bartłomiej Piotrowski (Barthalion)
Wednesday, 09 November 2016, 20:15 GMT
Reason for closing:  Fixed
Additional comments about closing:  bash 4.4-1
Comment by Alain Kalker (ackalker) - Friday, 16 September 2016, 04:35 GMT
Scratch the example of debug tracing using PS4 (i forgot that sometimes I need to run the script with sudo, which clears out PS4 on its own).
The part about setting variables in /etc/bash.bashrc still holds.
Comment by Alain Kalker (ackalker) - Friday, 16 September 2016, 04:42 GMT
Corrected example:

$ export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
$ bash -x

This should trace (with source/line/function info) startup scripts as for an interactive shell, but currently doesn't.
Comment by Bartłomiej Piotrowski (Barthalion) - Wednesday, 09 November 2016, 20:15 GMT
I don't like the default PS1 so I kept that one. The rest is gone.

Loading...