Chet Ramey <[EMAIL PROTECTED]> writes:

>> Machine Type: i486-pc-linux-gnu
>> 
>> Bash Version: 3.2
>> Patch Level: 39
>> Release Status: release
>> 
>> Description:
>> 
>> \w in PS1 prompt string confuses bash when ending in \
>> 
>>      The standard prompt setting in ubuntu is
>> PS1="${debian_chroot:+($debian_chroot)[EMAIL PROTECTED]:\w\$"
>> 
>> which seems harmless enough.  However, if you do
>> 
>> mkdir /tmp/chaos\\ ; cd /tmp/chaos\\
>> 
>> the prompt display hopelessly confuses bash.  At first it displays
>> nothing at all, then with repeated entries of RET fragments of color
>> ANSI sequences appear, like
>> 
>> [EMAIL PROTECTED]:/tmp/xxx$ mkdir /tmp/chaos\\ ; cd /tmp/chaos\\
>> ]0;[EMAIL PROTECTED]: /tmp/[EMAIL PROTECTED]:/tmp/chaos\$ 
>> ]0;[EMAIL PROTECTED]: /tmp/[EMAIL PROTECTED]:/tmp/chaos\$ 
>
> Since bash doesn't output any of that by default, I suspect you have
> something in PROMPT_COMMAND that tries to write to an xterm title bar
> and is confused by the escape at the end of the prompt string.

Bingo.  At my home machine, I don't have this effect.  This comes (for
new users) from

/etc/skel/.bashrc

where we have

# If this is an xterm set the title to [EMAIL PROTECTED]:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;[EMAIL PROTECTED]: ${PWD/$HOME/~}\007"'
    ;;
*)
    ;;
esac

And this is in the package bash-3.2-0ubuntu18

It would appear that the trailing backslash in combination with echo -e
combines with the backslash of \007 and leaves a literal 007 afterwards.

[EMAIL PROTECTED]:/tmp/xxx\$ echo "\007"
\007
[EMAIL PROTECTED]:/tmp/xxx\$ echo -e "\007"

[EMAIL PROTECTED]:/tmp/xxx\$ echo "${PWD/$HOME/~}\007"
/tmp/xxx\\007
[EMAIL PROTECTED]:/tmp/xxx\$ echo -e "${PWD/$HOME/~}\007"
/tmp/xxx\007

Since PWD can contain backslashes at arbitrary positions, echo -e is
clearly inappropriate here.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum


Reply via email to