From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Thu, 4 Feb 1999 15:36:10 -0700 (MST) From: Steve Talley Message-Id: <199902042236.PAA11357@ipecac.Central.Sun.COM> To: zsh-users@math.gatech.edu Subject: globbing for links in pathnames X-Mailing-List: 2090 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Thu, 4 Feb 1999 18:27:43 -0500 From: Sweth Chandramouli To: zsh-users@math.gatech.edu Subject: Re: globbing for links in pathnames Message-ID: <19990204182743.A19812@astaroth.nit.gwu.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailing-List: 2091 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 / (202) 994 - 8521 (V) / (202) 994 - 0458 (F) * From mboxrd@z Thu Jan 1 00:00:00 1970 Message-Id: <199902050024.RAA17645@empire.Central.Sun.COM> Date: Thu, 4 Feb 1999 17:23:32 -0700 (MST) From: Steve Talley Reply-To: Steve Talley Subject: Re: globbing for links in pathnames To: sweth@astaroth.nit.gwu.edu Cc: zsh-users@math.gatech.edu MIME-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii X-Mailing-List: 2093 > > 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Bart Schaefer" Message-Id: <990204165600.ZM19580@candle.brasslantern.com> Date: Thu, 4 Feb 1999 16:56:00 -0800 To: zsh-users@math.gatech.edu Subject: Re: globbing for links in pathnames MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailing-List: 2094 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(/)' From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Thu, 4 Feb 1999 23:11:38 -0500 From: Sweth Chandramouli To: zsh-users@math.gatech.edu Subject: Re: globbing for links in pathnames Message-ID: <19990204231138.A20361@astaroth.nit.gwu.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailing-List: 2096 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 / (202) 994 - 8521 (V) / (202) 994 - 0458 (F) * From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Thu, 4 Feb 1999 23:22:19 -0500 From: Sweth Chandramouli To: zsh-users@math.gatech.edu Subject: Re: globbing for links in pathnames Message-ID: <19990204232219.B20361@astaroth.nit.gwu.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailing-List: 2097 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 / (202) 994 - 8521 (V) / (202) 994 - 0458 (F) * From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Bart Schaefer" Message-Id: <990204210755.ZM20448@candle.brasslantern.com> Date: Thu, 4 Feb 1999 21:07:55 -0800 To: Sweth Chandramouli , zsh-users@math.gatech.edu Subject: Re: globbing for links in pathnames MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailing-List: 2098 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <19990205120648.G17215@fysh.org> Date: Fri, 5 Feb 1999 12:06:48 +0000 From: Phil Pennock To: zsh-users@math.gatech.edu Subject: Re: globbing for links in pathnames Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailing-List: 2103 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? From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <36BAFF36.7B5A5154@earthling.net> Date: Fri, 05 Feb 1999 14:24:55 +0000 From: Andrew Gallagher MIME-Version: 1.0 To: zsh-users@math.gatech.edu Subject: Re: globbing for links in pathnames Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailing-List: 2104 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Bart Schaefer" Message-Id: <990205091428.ZM23509@candle.brasslantern.com> Date: Fri, 5 Feb 1999 09:14:28 -0800 To: zsh-users@math.gatech.edu Subject: Re: globbing for links in pathnames MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailing-List: 2105 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