[Top][All Lists]

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

Re: PS1 prompt problem

From: Andreas Schwab
Subject: Re: PS1 prompt problem
Date: Fri, 16 Oct 2009 20:53:22 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Nils <address@hidden> writes:

> Following a suggestion in comp.unix.shell putting the above code
> contained in $() inside a separate function f and setting PS1='$( f )'
> displays the $spwd correctly in both the prompt and xterm title, but
> bash escapes like "\u", "\h" etc are not expanded any more

You could pass them as arguments to the function.

> What's wrong here?

You are faced with multi-level expansion and need to protect the special
characters that you want to be preserved for the later levels.  Before
the command substitution is expanded all backslash sequences are
expanded, so for example "\033_%s\033\\" becomes "^[_%s^[\" (where ^[
denotes the literal escape character).  The trailing backslash is now
quoting the quote character, which results in an unmatched quote.  Thus
you should write "\\033_%s\\033\\\\" instead.

    [[ ${#spwd} -gt 10 ]] && spwd="...${spwd: -10}"
    printf "address@hidden:%s%s " "\u" "\h" "${spwd}" "\$"

    printf "%s" "\["
    case "${TERM}" in
            printf "\\033]0;%s\\a" "${termtitle}"
            printf "\\033_%s\\033\\\\" "${termtitle}"
    printf "%s" "\]"


Andreas Schwab, address@hidden
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

reply via email to

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