bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: \w in PS1 hopelessly confuses bash in workdir ending in \


From: David Kastrup
Subject: Re: \w in PS1 hopelessly confuses bash in workdir ending in \
Date: Wed, 06 Aug 2008 23:37:22 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Chet Ramey <chet.ramey@case.edu> 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)}\u@\h:\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
>> 
>> dak@lisa:/tmp/xxx$ mkdir /tmp/chaos\\ ; cd /tmp/chaos\\
>> ]0;dak@lisa: /tmp/chaos\007dak@lisa:/tmp/chaos\$ 
>> ]0;dak@lisa: /tmp/chaos\007dak@lisa:/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 user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${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.

dak@lola:/tmp/xxx\$ echo "\007"
\007
dak@lola:/tmp/xxx\$ echo -e "\007"

dak@lola:/tmp/xxx\$ echo "${PWD/$HOME/~}\007"
/tmp/xxx\\007
dak@lola:/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

[Prev in Thread] Current Thread [Next in Thread]