[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: another problem with bash PS1 handling
From: |
Chet Ramey |
Subject: |
Re: another problem with bash PS1 handling |
Date: |
Sun, 18 Oct 2009 20:56:03 -0400 |
User-agent: |
Thunderbird 2.0.0.23 (Macintosh/20090812) |
Nils wrote:
> PS1='$( [ "${LOGNAME}" != root ] && color=green )'
>
> works in ksh93 and POSIX shell but fails in bash as bash seems to
> expand the "!" to the next history file number before doing command
> substitution. Setting PS1='$( [ "${LOGNAME}" !!= root ] &&
> color=green )' preserves the "!" and works in bash but fails in ksh93
> and POSIX shell.
There are several issues at play here. First, this only occurs when
bash is in posix mode, since that's the only time it attempts to do
the posix-style history substitution in the prompt strings.
Second, there are a couple of problems with Posix and this construct.
You can make an argument that Posix doesn't apply, since it only
calls for parameter expansion on the value of PS1, and that does not
include command substitution. Even if it does apply, it's not clear
whether or not the expansion of ! to the history number should be
performed before or after the word expansions. Bash chooses to do it
before the expansion, since that's when it's scanning the string for
the other backslash-prefixed expansions it performs, and it looks like
ksh does it after the word expansions.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/