Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: The ~ parameter expansion flag: bug or misunderstanding
- X-seq: zsh-workers 33133
- From: Clint Hepner <clint.hepner@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: The ~ parameter expansion flag: bug or misunderstanding
- Date: Tue, 9 Sep 2014 12:21:16 -0400
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=82FnMsJqdFPV+YlqcKjzNM+LVZqe1rnAkHAGNY8lUSI=; b=CThfXmeM4R7Md/P4qIyPef4yCcZA66F8EeCW3ziNdAleOq9q9LlQ28KApLZWFyvAvl hXSYwzGVP2Rfv1Zy3G4TeXVORn6c6te5TMp1oIsj1+sjyB+y8wt9pGBQDGlXqXPtC08G cn8hCRsaT6hwa7N38u03yCxAsIuJbXu32oyXsgtSQz4sQcKaxC9VeoMlwCtqdf8M17+L hHDb2+7/PL9f9HHvJjIgaw4yq/9yedIfoEQ5b+ee65QVBzHQw5RWR4L39TWpmNzIl4ZX TJKIuzKLtHjAYjMmS+CGgTgjKV1x1nrBS1bZFMJTZRDuFpkqWgh2XStrGQvGOVk96vzd 0wVw==
- In-reply-to: <140903084448.ZM16438@torch.brasslantern.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAKjp4B7-EeMzsXWO6O7LjPCSEhurXsCC4f2K_-cjV-5vC_h1CQ@mail.gmail.com> <140903084448.ZM16438@torch.brasslantern.com>
Thanks. One thing I still can't quite wrap my mind around is a scenario
where
${(j.|.)~array}
and
${~j.|.)array}
would behave differently. I assume it would involve some additional
modifications made to $array; I tried something like
array=(foo bar)
[[ "?" = ${(~j.|.)array:s/foo/?/} ]] # match
[[ "?" = ${(j.|.)~array:s/foo/?/} ]] # match
but that was not sufficient.
On Wed, Sep 3, 2014 at 11:44 AM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
wrote:
> On Sep 3, 10:58am, Clint Hepner wrote:
> }
> } My reading of the ~ flag leads me to believe that you can replace the
> } literal string with a pattern, so that
> }
> } % print -l ${(~s.[12].):-a1b2c}
> } a
> } b
> } c
>
> No, that's not what the flag means. It means that after the expansion
> of the parameter has been completed, any pattern characters inserted
> into the result are active (i.e., not considered quoted). It doesn't
> otherwise change the operation of the other flags themselves.
>
> This doesn't have any effect for the (s) flag because (s) removes
> characters from the result, rather than inserting them.
>
> The purpose of the (~) flag is really to work with the (j) flag, so
> that you can create a pattern from an array without having any other
> pattern characters in the values of the array also become active.
> It also works with (l) and (r), though the uses for treating padding
> as pattern characters are pretty obscure.
>
> To use a pattern for processing the value during expansion, you need
> to use the trailing // notation, e.g.
>
> % print -l ${=${:-a1b2c}//[12]/ }
>
> or
>
> % print -l ${(s:1:)${:-a1b2c}//[12]/1}
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author