Bug 678 - /etc/bashrc sets PS1 at inappropriate times
Summary: /etc/bashrc sets PS1 at inappropriate times
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: bash
Version: 5.2
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: David Lawrence
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 1999-01-03 22:06 UTC by Ted Powell
Modified: 2008-05-01 15:37 UTC (History)
0 users

Fixed In Version:
Clone Of:
Environment:
Last Closed: 1999-01-05 00:25:13 UTC
Embargoed:


Attachments (Terms of Use)

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.


Note You need to log in before you can comment on or make changes to this bug.