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

Re: mapfile, many files and globbin



On Mon, Jun 3, 2013 at 7:00 AM, Wawrzek Niewodniczanski
<main@xxxxxxxxxxxx>wrote:

> Hi,
>
> Is it possible to mix mapfile module and globbing (for file names)?
>

Partly, but not in the way you want.  You can mix mapfile and pattern
matching but not mapfile and glob flags that reference on-disk file
attributes, including recursive directory descent.  So in your example:

names=("${(f)mapfile[TEST/**/*list(.L+0)]}")
>

The **/ and (.L+0) won't work.  mapfile is just an associative array, so
you can only do associative array key matching in the subscript expression.
 Also, the keys of $mapfile that you can examine are limited to the names
of files in the current working directory, and you can't [in a single
non-nested parameter expression] expand the contents of a file name matched
by a subscript pattern.

Similarly ${mapfile[(R)pattern]} will not do a grep for you.

However, you can invert the problem and mix globbing with mapfile.

names=( TEST/**/*list(.L+0e:'reply=(${(f)mapfile[$REPLY]})':) )

If you don't want the results sorted, you may need some additional flags.


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