zsh-users
 help / color / mirror / code / Atom feed
* glob inside nested parameter expansion returns glob string
@ 2022-04-21 17:24 Jim
  2022-04-21 18:51 ` Mikael Magnusson
  0 siblings, 1 reply; 5+ messages in thread
From: Jim @ 2022-04-21 17:24 UTC (permalink / raw)
  To: zsh

[-- Attachment #1: Type: text/plain, Size: 362 bytes --]

Hi,

The following two statements produce the expected results:

% A=(${:-.z*(.N)})
% A=(${A:#*(comp|hist)*})

When trying to nest the two, the result is the glob statement:

A=(${${:-.z*(.N)}:#*(comp|hist)*})

Trying to understand why this is the case.  Could someone explain why this
happens?
Is there a way to nest the two?

Thanks for your help,

Jim Murphy

[-- Attachment #2: Type: text/html, Size: 588 bytes --]

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

* Re: glob inside nested parameter expansion returns glob string
  2022-04-21 17:24 glob inside nested parameter expansion returns glob string Jim
@ 2022-04-21 18:51 ` Mikael Magnusson
  2022-04-21 19:15   ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Mikael Magnusson @ 2022-04-21 18:51 UTC (permalink / raw)
  To: linuxtechguy; +Cc: zsh

On 4/21/22, Jim <linux.tech.guy@gmail.com> wrote:
> Hi,
>
> The following two statements produce the expected results:
>
> % A=(${:-.z*(.N)})
> % A=(${A:#*(comp|hist)*})
>
> When trying to nest the two, the result is the glob statement:
>
> A=(${${:-.z*(.N)}:#*(comp|hist)*})
>
> Trying to understand why this is the case.  Could someone explain why this
> happens?
> Is there a way to nest the two?

There is a certain order that parameter expansions and globs happen
relative to eachother, nesting param expansions does not change the
order of processing. Eg, there is not really any way you can process
.z* before the outer :# happens, which will operate on the
pre-expanded string in your final combined statement. In short, no(t
as far as I know).

-- 
Mikael Magnusson


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

* Re: glob inside nested parameter expansion returns glob string
  2022-04-21 18:51 ` Mikael Magnusson
@ 2022-04-21 19:15   ` Bart Schaefer
  2022-04-21 20:37     ` Jim
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2022-04-21 19:15 UTC (permalink / raw)
  To: linuxtechguy; +Cc: zsh

On Thu, Apr 21, 2022 at 11:51 AM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> On 4/21/22, Jim <linux.tech.guy@gmail.com> wrote:
> >
> > % A=(${:-.z*(.N)})
> > % A=(${A:#*(comp|hist)*})
> >
> > Is there a way to nest the two?
>
> There is a certain order that parameter expansions and globs happen
> relative to eachother [...] In short, no(t as far as I know).

Correct, this can't be done as a nested expansion, except by invoking
a subshell to perform the globbing.

A=(${${(@f):-$(print -rl .z*(.N))}:#*(comp|hist)*})

However, with extendedglob this specific example can be done entirely
with globbing:

A=( .z*~*(comp|hist)*(.N) )


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

* Re: glob inside nested parameter expansion returns glob string
  2022-04-21 19:15   ` Bart Schaefer
@ 2022-04-21 20:37     ` Jim
  2022-04-21 21:00       ` Jim
  0 siblings, 1 reply; 5+ messages in thread
From: Jim @ 2022-04-21 20:37 UTC (permalink / raw)
  To: zsh

[-- Attachment #1: Type: text/plain, Size: 1082 bytes --]

Thanks everyone for the responses.

On Thu, Apr 21, 2022 at 2:15 PM Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Thu, Apr 21, 2022 at 11:51 AM Mikael Magnusson <mikachu@gmail.com>
> wrote:
> >
> > On 4/21/22, Jim <linux.tech.guy@gmail.com> wrote:
> > >
> > > % A=(${:-.z*(.N)})
> > > % A=(${A:#*(comp|hist)*})
> > >
> > > Is there a way to nest the two?
> >
> > There is a certain order that parameter expansions and globs happen
> > relative to eachother [...] In short, no(t as far as I know).
>
> Correct, this can't be done as a nested expansion, except by invoking
> a subshell to perform the globbing.
>
> A=(${${(@f):-$(print -rl .z*(.N))}:#*(comp|hist)*})
>

Came fairly close on this one while trying different ways.  Didn't use a
print
command. :-(

However, with extendedglob this specific example can be done entirely
> with globbing:
>
> A=( .z*~*(comp|hist)*(.N) )
>

Is there a typo or something missing here? This didn't find any files when I
cut and pasted it in a shell.

ZSH_VERSION  5.8
ZSH_PATCHLEVEL  debian/5.8-6+deb11u1

Again, thanks,

Jim Murphy

[-- Attachment #2: Type: text/html, Size: 1935 bytes --]

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

* Re: glob inside nested parameter expansion returns glob string
  2022-04-21 20:37     ` Jim
@ 2022-04-21 21:00       ` Jim
  0 siblings, 0 replies; 5+ messages in thread
From: Jim @ 2022-04-21 21:00 UTC (permalink / raw)
  To: zsh

[-- Attachment #1: Type: text/plain, Size: 1265 bytes --]

Sorry, thought I had extendedglob set, works fine.

On Thu, Apr 21, 2022 at 3:37 PM Jim <linux.tech.guy@gmail.com> wrote:

> Thanks everyone for the responses.
>
> On Thu, Apr 21, 2022 at 2:15 PM Bart Schaefer <schaefer@brasslantern.com>
> wrote:
>
>> On Thu, Apr 21, 2022 at 11:51 AM Mikael Magnusson <mikachu@gmail.com>
>> wrote:
>> >
>> > On 4/21/22, Jim <linux.tech.guy@gmail.com> wrote:
>> > >
>> > > % A=(${:-.z*(.N)})
>> > > % A=(${A:#*(comp|hist)*})
>> > >
>> > > Is there a way to nest the two?
>> >
>> > There is a certain order that parameter expansions and globs happen
>> > relative to eachother [...] In short, no(t as far as I know).
>>
>> Correct, this can't be done as a nested expansion, except by invoking
>> a subshell to perform the globbing.
>>
>> A=(${${(@f):-$(print -rl .z*(.N))}:#*(comp|hist)*})
>>
>
> Came fairly close on this one while trying different ways.  Didn't use a
> print
> command. :-(
>
> However, with extendedglob this specific example can be done entirely
>> with globbing:
>>
>> A=( .z*~*(comp|hist)*(.N) )
>>
>
> Is there a typo or something missing here? This didn't find any files when
> I
> cut and pasted it in a shell.
>
> ZSH_VERSION  5.8
> ZSH_PATCHLEVEL  debian/5.8-6+deb11u1
>
> Again, thanks,
>
> Jim Murphy
>

[-- Attachment #2: Type: text/html, Size: 2362 bytes --]

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

end of thread, other threads:[~2022-04-21 21:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-21 17:24 glob inside nested parameter expansion returns glob string Jim
2022-04-21 18:51 ` Mikael Magnusson
2022-04-21 19:15   ` Bart Schaefer
2022-04-21 20:37     ` Jim
2022-04-21 21:00       ` Jim

Code repositories for project(s) associated with this 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).