On 3/24/17 11:57 PM, Torka Noda wrote: > Hi, > > (Currently using Bash-4.4_p12 on Gentoo GNU/Linux). > > My PS1 contains colors, and thus \[ ... \] sequences around > colors, for proper line wrapping on the command-line. > > I want to fake this prompt from my ~/.bashrc, because OCD, > before I execute some commands printing stuffs in the shell. > > The problem is, using `echo -e "${PS1@P}ls"` will show > glyphs for the non-printing characters "\[" and "\]", instead > of stripping them. > > From what I understand, \[ and \] characters are only useful for > the prompts, right?
Yes, but one of the primary motivations for including the @P modifier was requests to be able to use prompt expansions when using `read -e -p'. In this case, you have to have the escape sequences preserved. > If so, then the parameter operator P should probably strip them. In general, you want the \[ and \] sequences expanded in all cases where the result will eventually be fed to readline, and stripped when it is not. It's not feasible for bash to figure that out for itself, so you have to tell it. Since those escape sequences get stripped when bash isn't going to be doing line editing, you can put `set +o emacs +o vi' (or whichever one is relevant for you) before expanding a string using the @P modifier and get the results you want. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/