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

Re: Another expansion (substitution?) question



Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> writes:
> On Jul 8,  1:57pm, Vin Shelton wrote:
> } Subject: Another expansion (substitution?) question
> }
> }     print -l ${(ou)${^$(all_dirs)}/$=~^*(N/:t)}
> }     zsh: bad pattern: emacs* o*(N
>
> There are three problems here.  One, you can't use an expansion that
> does not have braces (in this case "$=~^*") nested inside an expansion
> that does have braces.  So you'd at least have to write (the following
> is not a working substitution):
>
> 	${(ou)${^$(all_dirs)}/${=~^*}(N/:t)}
>
> However, problem two, globbing is not applied inside a nested expansion
> so your "(N/:t)" qualifiers are useless; and problem three, a slash in
> a brace-expansion is (as you found) a pattern substitution operator, as
> is two slashes, which is why doubling it didn't work; and three slashes
> in a row is probably being interpreted as substituting the empty string
> for all occurrences of the empty string.
>
> }     x=( ${^$(all_dirs)}/$=~^*(N/:t) )
> }     print -l ${(ou)x}
>
> The only way to reduce that to a one-liner is to use another subshell
> like so:
>
> 	print -l ${(ouf)"$(print -l ${^$(all_dirs)}/$=~^*(N/:t))"}
>
> This is probably not worth the expense of the extra fork and I/O.  Stick
> with the two-liner using the temporary.

Thanks for the explanation, Bart.

  - Vin



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