Bug 678

Summary: /etc/bashrc sets PS1 at inappropriate times
Product: [Retired] Red Hat Linux Reporter: Ted Powell <ted>
Component: bashAssignee: David Lawrence <dkl>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 5.2   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 1999-01-05 00:25:13 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Ted Powell 1999-01-03 22:06:12 UTC
The version of /etc/bashrc contained in bash-1.14.7-13 is as
follows:

  # /etc/bashrc

  # System wide functions and aliases
  # Environment stuff goes in /etc/profile

  # For some unknown reason bash refuses to inherit
  # PS1 in some circumstances that I can't figure out.
  # Putting PS1 here ensures that it gets loaded every time.
  PS1="[\u@\h \W]\\$ "

  alias which="type -path"

RTFM.

Searching the BASH(1) man page for the string "PS1" gets a
hit in the INVOCATION section, which reads in part:

"PS1 is set ... if bash is interactive, allowing a shell
script or a startup file to test this state."

Setting PS1 unconditionally, as is done by the current
/etc/bashrc, breaks this facility.

If it is desired to set PS1, when appropriate, to a specific
string, this can be done with:

  # PS1 is only supposed to be set for an interactive shell.
  # Since this is the only easy test for an
interactive        # shell, it should not be tampered with.
  #
  if [ x${PS1+set} = xset ]; then
      # interactive
      PS1="[\u@\h \W]\\$ "
  fi

Three reasons why a user should be able to use a simple test
(namely, seeing whether PS1 is set) for whether the current
shell is interactive:

3. ``stty </dev/tty erase ^H'' gets an annoying complaint
if    the shell is not interactive.

2. Operations such as updating the window title bar
generate    unacceptable overhead if done in a long-running
script.

1. BASH(1) SAYS YOU CAN DO IT.

Comment 1 David Lawrence 1999-01-05 00:25:59 UTC
Thank you for the suggestion. It has been noted and will be considered
for future releases of Red Hat.