Nils <nils.bernh...@yahoo.de> 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. PS1='$( spwd="${PWD/#${HOME}/~}" [[ ${#spwd} -gt 10 ]] && spwd="...${spwd: -10}" printf "%...@%s:%s%s " "\u" "\h" "${spwd}" "\$" termtitle="\...@\h:${spwd}" #### printf "%s" "\[" case "${TERM}" in (xterm*) printf "\\033]0;%s\\a" "${termtitle}" ;; (screen*) printf "\\033_%s\\033\\\\" "${termtitle}" ;; esac printf "%s" "\]" #### )' Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."