[Top][All Lists]

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

Re: PS1 prompt problem

From: Nils
Subject: Re: PS1 prompt problem
Date: Fri, 16 Oct 2009 12:50:49 -0700 (PDT)
User-agent: G2/1.0

On 16 Okt., 21:18, Chet Ramey <address@hidden> wrote:
> Sort of.  I think you're overlooking the various expansion (and backslash
> escaping) that's taking place with your prompt.
> Since you set the value of PS1 to literal string containing a command
> substitution, the value will be expanded twice before being sent to
> readline.  The first expansion is the normal set of backslash escapes
> performed by prompt string decoding; the second is the set of shell word
> expansions, including command substitution.
> This is the problem line: printf "\033_%s\033\\" "${termtitle}".  I
> assume the intent is to wind up with a string ending with a single
> backslash written to the terminal.  The string as written results in
> a parsing error.
> One of the prompt string decoding expansions turns \\ into \, so the
> form of the above string when passed to the parser by the command
> substitution is
>         printf "ESC_%sESC\" "${termtitle}"
> (the ESC stands for a literal escape character).  The escaped double quote
> is probably not what's intended.
> For printf to see what you want it to, you need to double the backslashes
> in that string:
>         printf "\033_%s\033\\\\" "${termtitle}"
> Try that and see what you get.

Yes, that was the problem, I did not take into account that bash
expands $PS1 twice. This is easy to reproduce by setting PS1='$
( printf "\\" )' which works with ash, ksh93, ksh88 but fails with
bash which needs PS1='$( printf "\\\\" )'. Is this double expansion
even POSIX compliant? The spec says that "[e]ach time an interactive
shell is ready to read a command, the value of this variable shall be
subjected to parameter expansion..." (http://www.opengroup.org/

reply via email to

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