zsh-users
 help / color / mirror / code / Atom feed
* Another expansion (substitution?) question
@ 2003-07-08 17:57 Vin Shelton
  2003-07-09  4:42 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Vin Shelton @ 2003-07-08 17:57 UTC (permalink / raw)
  To: Zsh users

Sorry for more questions, but I can't quite figure this one out.

I have a short function that lists all the matching sub-directories
under a list of directories.  This single line is most of the
function:

    print -l ${^$(all_dirs)}/$=~^*(N/:t) | sort -u

I thought I'd like to get rid of the 'sort -u' process, but I can't do
it all in one step.  The following works:

    x=( ${^$(all_dirs)}/$=~^*(N/:t) )
    print -l ${(ou)x}

but when I try to remove the temporary assignment to x, here is what I
get:

    print -l ${(ou)${^$(all_dirs)}/$=~^*(N/:t)}
    zsh: bad pattern: emacs* o*(N

It looks to me that what is happening is that the / is being
interpreted as starting a substitution.  I've tried doubling and
tripling the /, and I've tried quoting the / with a \, but nothing has
produced the desired effect.

I'm running with the latest CVS version, but I see similar problems
with 4.0.7.

Thanks for your time,
  Vin


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Another expansion (substitution?) question
  2003-07-08 17:57 Another expansion (substitution?) question Vin Shelton
@ 2003-07-09  4:42 ` Bart Schaefer
  2003-07-09  4:48   ` Vin Shelton
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2003-07-09  4:42 UTC (permalink / raw)
  To: Zsh users

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Another expansion (substitution?) question
  2003-07-09  4:42 ` Bart Schaefer
@ 2003-07-09  4:48   ` Vin Shelton
  0 siblings, 0 replies; 3+ messages in thread
From: Vin Shelton @ 2003-07-09  4:48 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh users

Bart Schaefer <schaefer@brasslantern.com> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-07-09  4:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-08 17:57 Another expansion (substitution?) question Vin Shelton
2003-07-09  4:42 ` Bart Schaefer
2003-07-09  4:48   ` Vin Shelton

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).