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

Re: The ~ parameter expansion flag: bug or misunderstanding



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