* mapfile, many files and globbin
@ 2013-06-03 14:00 Wawrzek Niewodniczanski
2013-06-03 15:44 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Wawrzek Niewodniczanski @ 2013-06-03 14:00 UTC (permalink / raw)
To: zsh-users
Hi,
Is it possible to mix mapfile module and globbing (for file names)?
In example I have following tree structure and try to put the content
of not empty list file (ideally one per file) to an array.
TEST/1/4/A.list
aaa
bbb
ccc
TEST/2/2/B.list
ddd
eee
fff
TEST/2/3/C.list - empty
I tried various of version around following command:
names=("${(f)mapfile[TEST/**/*list(.L+0)]}")
I will be glad for any suggestions.
Thanks,
Wawrzek
PS.
Eventually, gave up using:
names=($(cat TEST/**/*.list(.L+0)))
--
Dr Wawrzyniec Niewodniczański or Wawrzek for short
PhD in Quantum Chemistry & MSc in Molecular Engineering
WWW: http://wawrzek.name E-MAIL: jobs@wawrzek.name
Linux User #177124
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: mapfile, many files and globbin
2013-06-03 14:00 mapfile, many files and globbin Wawrzek Niewodniczanski
@ 2013-06-03 15:44 ` Bart Schaefer
2013-06-05 21:30 ` Wawrzek Niewodniczanski
0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2013-06-03 15:44 UTC (permalink / raw)
To: Zsh Users
[-- Attachment #1: Type: text/plain, Size: 1086 bytes --]
On Mon, Jun 3, 2013 at 7:00 AM, Wawrzek Niewodniczanski
<main@wawrzek.name>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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: mapfile, many files and globbin
2013-06-03 15:44 ` Bart Schaefer
@ 2013-06-05 21:30 ` Wawrzek Niewodniczanski
2013-06-06 6:17 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Wawrzek Niewodniczanski @ 2013-06-05 21:30 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh Users
On 3 June 2013 16:44, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Mon, Jun 3, 2013 at 7:00 AM, Wawrzek Niewodniczanski
> <main@wawrzek.name>wrote:
>
Hello,
[...]
Thanks for deep explanation.
I have following technical question to your example:
> names=( TEST/**/*list(.L+0e:'reply=(${(f)mapfile[$REPLY]})':) )
I just tested it and got:
names=( TEST/**/*list(.L+0e:'reply=(${(f)mapfile[$REPLY]})':) )
zsh: bad floating point constant
zsh: bad floating point constant
zsh: no matches found: TEST/**/*list(.L+0e:reply=(${(f)mapfile[$REPLY]}):)
What's wrong?
Wawrzek
--
Dr Wawrzyniec Niewodniczański or Wawrzek for short
PhD in Quantum Chemistry & MSc in Molecular Engineering
WWW: http://wawrzek.name E-MAIL: jobs@wawrzek.name
Linux User #177124
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: mapfile, many files and globbin
2013-06-05 21:30 ` Wawrzek Niewodniczanski
@ 2013-06-06 6:17 ` Bart Schaefer
0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2013-06-06 6:17 UTC (permalink / raw)
To: Wawrzek Niewodniczanski; +Cc: Zsh Users
On Jun 5, 10:30pm, Wawrzek Niewodniczanski wrote:
}
} I just tested it and got:
}
} names=( TEST/**/*list(.L+0e:'reply=(${(f)mapfile[$REPLY]})':) )
} zsh: bad floating point constant
} zsh: bad floating point constant
} zsh: no matches found: TEST/**/*list(.L+0e:reply=(${(f)mapfile[$REPLY]}):)
}
} What's wrong?
You don't have the zsh/mapfile module loaded, so $mapfile is being
treated as an ordinary array and the subscript (that is, each file's
name) is being interpreted as an arithmetic expression.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-06-06 14:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-03 14:00 mapfile, many files and globbin Wawrzek Niewodniczanski
2013-06-03 15:44 ` Bart Schaefer
2013-06-05 21:30 ` Wawrzek Niewodniczanski
2013-06-06 6:17 ` Bart Schaefer
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).