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

Re: globbing for links in pathnames



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



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