zsh-users
 help / color / mirror / code / Atom feed
* Re: globbing for links in pathnames
@ 1999-02-05  5:07 Bart Schaefer
  0 siblings, 0 replies; 10+ messages in thread
From: Bart Schaefer @ 1999-02-05  5:07 UTC (permalink / raw)
  To: Sweth Chandramouli, zsh-users

On Feb 4, 11:22pm, Sweth Chandramouli wrote:
} Subject: Re: globbing for links in pathnames
}
} On Thu, Feb 04, 1999 at 04:56:00PM -0800, Bart Schaefer wrote:
} > zsh% setopt globassign
} > zsh% x=*(@) eval 'ls $^x/man(/)'
} 
} 	according to the docs, globassign is deprecated, because
} globbing is done implicitly so long as the parameter is explicitly
} set to an array.

D'oh!  I was distracted by attempting to get globbing to happen in the
right-side of ${x::=*(@)}, discovered that glob_assign wouldn't do it,
and then just left it there and typed the other solution.

} so it should end up something like the following:
} 
} x=(pkgs/*(@)) ; ls -d ${^x}/man(/)

The reason I used the eval was to avoid having x remain set after the
command completes.  `x=(*(@)) eval ...` will unset x again at the end
of the eval, and won't destroy any existing value of x.

zsh% x=START ; x=NEXT eval 'echo $x' ; echo $x
NEXT
START

} 	-- sweth, who is now wondering if he could combine this
} with the earlier discussion about nested expansion to make a single
} inscrutable argument to ls -d to achieve this via (P).

The new (P) flag won't help with this; it only does an extra level of
variable name lookup.

There's no way to get globbing to happen inside the ${...} expression
without using a command substitution.  So you could do

	ls -d pkgs/${^$(echo *(@))}/man(/)

but that actually has to fork a subshell for the $(...) so it's not as
efficient as the eval.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: globbing for links in pathnames
@ 1999-02-05 17:14 Bart Schaefer
  0 siblings, 0 replies; 10+ messages in thread
From: Bart Schaefer @ 1999-02-05 17:14 UTC (permalink / raw)
  To: zsh-users

On Feb 5,  2:24pm, Andrew Gallagher wrote:
} Subject: Re: globbing for links in pathnames
}
} Phil Pennock wrote:
} 
} > Okay, why do neither the second nor third ones here work "as expected"?
} >
} > % print -l ${(A)~x::=pkgs/*(@)}
} > pkgs/bar
} > pkgs/foo
} > % print -l ${(A)^~x::=pkgs/*(@)}/man
} > pkgs/*(@)/man
} > % print -l ${^${(A)~x::=pkgs/*(@)}}/man
} > pkgs/*(@)/man
} > %
} 
}  I can't tell you "why" this happens, but it seems that "how" it happens is
} that the "/man" is being appended to the result of the parameter expansion
} before globbing takes place. Evidently, when the ~ is processed it sets a
} flag which allows globbing to happen further down the line, rather than
} forcing globbing to happen at that point.

Mostly correct.

Normally zsh "tokenizes" the command line as it is parsed.  '*' is changed
into a character represented internally by the constant Star, '(' becomes
Inpar, '$' becomes String, etc.  (If the tokens themselves appear in the
input, they become a magic two-byte sequence.)  Globbing is invoked when
the Star token (among others) is seen when the input is re-scanned after
other expansions; the order in which expansions occur is in the manual.

Also normally, the parameter expansion code DOES NOT tokenize the string
that it returns, so Star et al. don't appear and no globbing happens.
What ~ does is cause the string to be tokenized.  That doesn't affect the
order of expansions, so globbing is now enabled but doesn't happen until
later.

(Maybe that's more than zsh-users want to know ....)

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: globbing for links in pathnames
@ 1999-02-05 14:24 Andrew Gallagher
  0 siblings, 0 replies; 10+ messages in thread
From: Andrew Gallagher @ 1999-02-05 14:24 UTC (permalink / raw)
  To: zsh-users

Phil Pennock wrote:

> Typing away merrily, Bart Schaefer produced the immortal words:
> > D'oh!  I was distracted by attempting to get globbing to happen in the
> > right-side of ${x::=*(@)}, discovered that glob_assign wouldn't do it,
> > and then just left it there and typed the other solution.
>
> Okay, why do neither the second nor third ones here work "as expected"?
>
> % print -l ${(A)~x::=pkgs/*(@)}given that:
> pkgs/bar
> pkgs/foo
> % print -l ${(A)^~x::=pkgs/*(@)}/man
> pkgs/*(@)/man
> % print -l ${^${(A)~x::=pkgs/*(@)}}/man
> pkgs/*(@)/man
> %
>

 I can't tell you "why" this happens, but it seems that "how" it happens is
that the "/man" is being appended to the result of the parameter expansion
before globbing takes place. Evidently, when the ~ is processed it sets a flag
which allows globbing to happen further down the line, rather than forcing
globbing to happen at that point.

--
Andrew Gallagher
http://members.tripod.com/~AndrewGallagher/id.html





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

* Re: globbing for links in pathnames
@ 1999-02-05 12:06 Phil Pennock
  0 siblings, 0 replies; 10+ messages in thread
From: Phil Pennock @ 1999-02-05 12:06 UTC (permalink / raw)
  To: zsh-users

Typing away merrily, Bart Schaefer produced the immortal words:
> D'oh!  I was distracted by attempting to get globbing to happen in the
> right-side of ${x::=*(@)}, discovered that glob_assign wouldn't do it,
> and then just left it there and typed the other solution.

Okay, why do neither the second nor third ones here work "as expected"?

% print -l ${(A)~x::=pkgs/*(@)}given that:
pkgs/bar
pkgs/foo
% print -l ${(A)^~x::=pkgs/*(@)}/man 
pkgs/*(@)/man
% print -l ${^${(A)~x::=pkgs/*(@)}}/man
pkgs/*(@)/man
% 

I'm a little confused.
-- 
--> Phil Pennock ; GAT d- s+:+ a23 C++(++++) UL++++/I+++/S+++/B++/H+$ P++@$
L+++ E-@ W(+) N>++ o !K w--- O>+ M V !PS PE Y+ PGP+ t-- 5++ X+ R !tv b++>+++
DI+ D+ G+ e+ h* r y?


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

* Re: globbing for links in pathnames
@ 1999-02-05  4:22 Sweth Chandramouli
  0 siblings, 0 replies; 10+ messages in thread
From: Sweth Chandramouli @ 1999-02-05  4:22 UTC (permalink / raw)
  To: zsh-users

On Thu, Feb 04, 1999 at 04:56:00PM -0800, Bart Schaefer wrote:
> On Feb 4,  6:27pm, Sweth Chandramouli wrote:
> > Subject: Re: globbing for links in pathnames
> > On Thu, Feb 04, 1999 at 03:36:10PM -0700, Steve Talley wrote:
> > > [...]  Is there a way to only specify the
> > > links (or non-links) in the glob?  Something like
> > > 
> > > % ls pkgs/*(@)/man
> > 
> > % ls $( ls -d test/*(@) )/man(/)
> 
> zsh% setopt globassign
> zsh% x=*(@) eval 'ls $^x/man(/)'

	according to the docs, globassign is deprecated, because
globbing is done implicitly so long as the parameter is explicitly
set to an array.  so it should end up something like the following:

x=(pkgs/*(@)) ; ls -d ${^x}/man(/)

	-- sweth, who is now wondering if he could combine this
with the earlier discussion about nested expansion to make a single
inscrutable argument to ls -d to achieve this via (P).

-- 
Sweth Chandramouli
IS Coordinator, The George Washington University
<sweth@gwu.edu> / (202) 994 - 8521 (V) / (202) 994 - 0458 (F)
<a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a>


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

* Re: globbing for links in pathnames
@ 1999-02-05  4:11 Sweth Chandramouli
  0 siblings, 0 replies; 10+ messages in thread
From: Sweth Chandramouli @ 1999-02-05  4:11 UTC (permalink / raw)
  To: zsh-users

On Thu, Feb 04, 1999 at 05:23:32PM -0700, Steve Talley wrote:
> > % ls $( ls -d test/*(@) )/man(/)
> 
> Thanks!  This is _almost_ what I want, but the above glob will
> only add the last part ("man") to the last element of the list
> from the earlier part.
> 
> So a general question is:  Is there a way to make
> 
> (a b c d)/man
> 
> expand to
> 
> a/man b/man c/man d/man

	the RC_EXPAND_PARAM option, which can be turned on/off
for a given expansion via the ${^...} construct:

(astaroth)~1: FOO=(a b c d)
(astaroth)~2: echo ${FOO}/man
a b c d/man
(astaroth)~3: echo ${^FOO}/man
a/man b/man c/man d/man

	-- sweth.

-- 
Sweth Chandramouli
IS Coordinator, The George Washington University
<sweth@gwu.edu> / (202) 994 - 8521 (V) / (202) 994 - 0458 (F)
<a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a>


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

* Re: globbing for links in pathnames
@ 1999-02-05  0:56 Bart Schaefer
  0 siblings, 0 replies; 10+ messages in thread
From: Bart Schaefer @ 1999-02-05  0:56 UTC (permalink / raw)
  To: zsh-users

On Feb 4,  6:27pm, Sweth Chandramouli wrote:
> Subject: Re: globbing for links in pathnames
> On Thu, Feb 04, 1999 at 03:36:10PM -0700, Steve Talley wrote:
> > [...]  Is there a way to only specify the
> > links (or non-links) in the glob?  Something like
> > 
> > % ls pkgs/*(@)/man
> 
> % ls $( ls -d test/*(@) )/man(/)

zsh% setopt globassign
zsh% x=*(@) eval 'ls $^x/man(/)'



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

* Re: globbing for links in pathnames
@ 1999-02-05  0:23 Steve Talley
  0 siblings, 0 replies; 10+ messages in thread
From: Steve Talley @ 1999-02-05  0:23 UTC (permalink / raw)
  To: sweth; +Cc: zsh-users

> 
> On Thu, Feb 04, 1999 at 03:36:10PM -0700, Steve Talley wrote:
> > Question:  I am trying to locate all directories called "man" one
> > level deep, ie:
> > 
> > % ls pkgs/*/man
> > 
> > will do it.  The trouble is, some of these are redundant (like
> > zsh-3.1.5/man and zsh/man).  Is there a way to only specify the
> > links (or non-links) in the glob?  Something like
> > 
> > % ls pkgs/*(@)/man
> 
> % ls pkgs/**/man(/) 
> 
> 	will find _all_ directories named man below the pkgs
> directory, but will _not_ follow symlinks.  (to do that, you
> would do `ls pkgs/***/man(/)' instead.)  if you want to limit
> your search to man directories one level deep (either so as
> to not list subsequent ones, or to not waste time searching
> large subdirectories that you aren't interested in), you're
> probably better off using find, or some kludge like
> 
> % ls $( ls -d test/*(@) )/man(/)

Thanks!  This is _almost_ what I want, but the above glob will
only add the last part ("man") to the last element of the list
from the earlier part.

So a general question is:  Is there a way to make

(a b c d)/man

expand to

a/man b/man c/man d/man

without using a for... clause?

Thanks,

Steve



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

* Re: globbing for links in pathnames
@ 1999-02-04 23:27 Sweth Chandramouli
  0 siblings, 0 replies; 10+ messages in thread
From: Sweth Chandramouli @ 1999-02-04 23:27 UTC (permalink / raw)
  To: zsh-users

On Thu, Feb 04, 1999 at 03:36:10PM -0700, Steve Talley wrote:
> Question:  I am trying to locate all directories called "man" one
> level deep, ie:
> 
> % ls pkgs/*/man
> 
> will do it.  The trouble is, some of these are redundant (like
> zsh-3.1.5/man and zsh/man).  Is there a way to only specify the
> links (or non-links) in the glob?  Something like
> 
> % ls pkgs/*(@)/man

% ls pkgs/**/man(/) 

	will find _all_ directories named man below the pkgs
directory, but will _not_ follow symlinks.  (to do that, you
would do `ls pkgs/***/man(/)' instead.)  if you want to limit
your search to man directories one level deep (either so as
to not list subsequent ones, or to not waste time searching
large subdirectories that you aren't interested in), you're
probably better off using find, or some kludge like

% ls $( ls -d test/*(@) )/man(/)

	-- sweth.

-- 
Sweth Chandramouli
IS Coordinator, The George Washington University
<sweth@gwu.edu> / (202) 994 - 8521 (V) / (202) 994 - 0458 (F)
<a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a>


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

* globbing for links in pathnames
@ 1999-02-04 22:36 Steve Talley
  0 siblings, 0 replies; 10+ messages in thread
From: Steve Talley @ 1999-02-04 22:36 UTC (permalink / raw)
  To: zsh-users

Hello,

I have a directory that looks like this:

%  ls -1 pkgs
./
../
gcc@
gcc-2.8.1/
perl@
perl-5.00502/
vim@
vim-5.4d/
zsh@
zsh-3.1.5/
...

In other words, there is a directory that contains a specific
package (ie. zsh-3.1.5) and a simplified link to that directory
(ie. zsh).

Question:  I am trying to locate all directories called "man" one
level deep, ie:

% ls pkgs/*/man

will do it.  The trouble is, some of these are redundant (like
zsh-3.1.5/man and zsh/man).  Is there a way to only specify the
links (or non-links) in the glob?  Something like

% ls pkgs/*(@)/man

The above doesn't work but is there something similar that will?

Thanks,

Steve


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

end of thread, other threads:[~1999-02-05 17:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-05  5:07 globbing for links in pathnames Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
1999-02-05 17:14 Bart Schaefer
1999-02-05 14:24 Andrew Gallagher
1999-02-05 12:06 Phil Pennock
1999-02-05  4:22 Sweth Chandramouli
1999-02-05  4:11 Sweth Chandramouli
1999-02-05  0:56 Bart Schaefer
1999-02-05  0:23 Steve Talley
1999-02-04 23:27 Sweth Chandramouli
1999-02-04 22:36 Steve Talley

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).