Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: The ~ parameter expansion flag: bug or misunderstanding



Ah, that makes sense: ${(j.|.)~array} treats *all* | as part of the
pattern, but `${(~j.|.)array}` treats only those added as part of the join
operation. Thank you.

On Tue, Sep 9, 2014 at 12:41 PM, Peter Stephenson <p.stephenson@xxxxxxxxxxx>
wrote:

> On Tue, 09 Sep 2014 12:21:16 -0400
> Clint Hepner <clint.hepner@xxxxxxxxx> wrote:
> > Thanks. One thing I still can't quite wrap my mind around is a scenario
> > where
> >
> >     ${(j.|.)~array}
> >
> > and
> >
> >     ${~j.|.)array}
> >
> > would behave differently.
>
> It depends on the contents of array.  Here's the sort of scenario that
> caused the ~ inside the parentheses to be added.
>
> Supposing someone has helpfully created a file "a|b", and your array is
> a list of files in the current directory,
>
> array=(*)
>
> so it contains an alement "a|b".  zsh with its default settings usually
> handles that fine because it makes a point of not expanding the results
> of variable substitutions as patterns for exactly this reason.
>
> However, when you do ${(j.|.)~array} it looks like two alternatives, a
> or b, because the "|" in the value of $array is expanded.
>
> If you do ${(~j.|.)array}, on the other hand, the "a|b" is kept with the
> | as an ordinary character, so it still works.
>
> pws
>


Messages sorted by: Reverse Date, Date, Thread, Author