[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Parameter operator P should probably strip \[ and \] characters
From: |
Torka Noda |
Subject: |
Re: Parameter operator P should probably strip \[ and \] characters |
Date: |
Mon, 27 Mar 2017 13:49:24 +0200 |
On Sat, 25 Mar 2017 15:16:31 -0400, Chet Ramey wrote:
>
> On 3/24/17 11:57 PM, Torka Noda wrote:
> > 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.
>
Oh, ok.
>
> > 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.
>
@p would strip \[ and \] characters, @P would not strip them? :)