|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
another problem with bash PS1 handlingPS1='$( [ "${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. |
|
|
Re: another problem with bash PS1 handlingNils 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@... http://cnswww.cns.cwru.edu/~chet/ |
|
|
|
|
|
Re: another problem with bash PS1 handling> Whether POSIX applies or not, from a logical standpoint history number > and custom bash escape expansion should be last, after parameter > expansion and command substitution because doing it first breaks > command substitution (see my earlier post) or using variables in a > prompt (a='!'; PS1='$a ' will result in a literal "!" rather than the > history number), it is unintuitive and deviates from the behavior of > other shells such as variants of ash and ksh. I disagree. I don't see a compelling reason to change 20 years of behavior here. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU chet@... http://cnswww.cns.cwru.edu/~chet/ |
| Free embeddable forum powered by Nabble | Forum Help |