* Problem with glob qualifier e
@ 2005-09-05 16:32 Hannu Koivisto
2005-09-05 17:22 ` Andrey Borzenkov
2005-09-05 18:39 ` Bart Schaefer
0 siblings, 2 replies; 6+ messages in thread
From: Hannu Koivisto @ 2005-09-05 16:32 UTC (permalink / raw)
To: Zsh Users' List
Greetings,
The manual of zsh 4.2.1 says the following about the glob qualifier
e:
filename. In addition, the parameter reply may be set to an array
or a string, which overrides the value of REPLY. If set to an
array, the latter is inserted into the command line word by word.
For example, suppose a directory contains a single file
`lonely'. Then the expression `*(e:'reply=(${REPLY}{1,2})':)'
will cause the words `lonely1 lonely2' to be inserted into the
command line.
I can verify that the example works as described. But I don't
understand how to extend that to more complex cases.
For instance, let's say that I would like to splice two command
line arguments after each file argument produced by a glob pattern.
If I have files sur and pur in the current directory, I would like
to say something along the lines of
echo (sur|pur)(e:'<something>':)
which, when expanded, should result to
echo pur -foo bar sur -foo bar
I expected
echo (sur|pur)(e:'reply=(${REPLY} -foo bar)':)
to do what I want but instead that results to
echo -foo -foo bar bar pur sur
I can't see how that follows from the quoted documentation. In any
case, if my goal cannot be achieved with the glob qualifier e, is
there some other brief trick to modify the list of generated
filenames in such a way?
--
Hannu
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem with glob qualifier e
2005-09-05 16:32 Problem with glob qualifier e Hannu Koivisto
@ 2005-09-05 17:22 ` Andrey Borzenkov
2005-09-05 19:05 ` Bart Schaefer
2005-09-05 18:39 ` Bart Schaefer
1 sibling, 1 reply; 6+ messages in thread
From: Andrey Borzenkov @ 2005-09-05 17:22 UTC (permalink / raw)
To: zsh-users; +Cc: Hannu Koivisto
[-- Attachment #1: Type: text/plain, Size: 923 bytes --]
On Monday 05 September 2005 20:32, Hannu Koivisto wrote:
[...]
> echo (sur|pur)(e:'<something>':)
>
> which, when expanded, should result to
>
> echo pur -foo bar sur -foo bar
>
> I expected
>
> echo (sur|pur)(e:'reply=(${REPLY} -foo bar)':)
>
> to do what I want but instead that results to
>
> echo -foo -foo bar bar pur sur
>
> I can't see how that follows from the quoted documentation.
List is sorted after all matches are added; meaning that anything you have
added is reordred. Hmm ... adding qualifier that prevents sorting is
relatively simple actually ...
> In any
> case, if my goal cannot be achieved with the glob qualifier e, is
> there some other brief trick to modify the list of generated
> filenames in such a way?
print -l sur pur | xargs -i /bin/echo '{}' -foo bar
(I do not know why xargs here won't process arguments seperated by spaces, it
should)
-andrey
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem with glob qualifier e
2005-09-05 17:22 ` Andrey Borzenkov
@ 2005-09-05 19:05 ` Bart Schaefer
2005-09-06 2:51 ` Andrey Borzenkov
0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2005-09-05 19:05 UTC (permalink / raw)
To: zsh-users
On Sep 5, 9:22pm, Andrey Borzenkov wrote:
}
} Hmm ... adding qualifier that prevents sorting is relatively simple
} actually ...
See discussion in zsh-workers/8702, 8704, 8705.
} print -l sur pur | xargs -i /bin/echo '{}' -foo bar
}
} (I do not know why xargs here won't process arguments seperated by
} spaces, it should)
I'm not sure what you mean? xargs never processes arguments separated
by spaces. It always wants newlines or NULs.
Anyway, there's also
zargs -i{} -- (sur|pur) -- echo {} -foo bar
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem with glob qualifier e
2005-09-05 19:05 ` Bart Schaefer
@ 2005-09-06 2:51 ` Andrey Borzenkov
2005-09-06 13:58 ` Bart Schaefer
0 siblings, 1 reply; 6+ messages in thread
From: Andrey Borzenkov @ 2005-09-06 2:51 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 541 bytes --]
On Monday 05 September 2005 23:05, Bart Schaefer wrote:
> }
> } (I do not know why xargs here won't process arguments seperated by
> } spaces, it should)
>
> I'm not sure what you mean? xargs never processes arguments separated
> by spaces. It always wants newlines or NULs.
>
then manual page is wrong:
This manual page documents the GNU version of xargs. xargs reads items
from the standard input, delimited by blanks (which can be protected
with double or single quotes or a backslash) or newlines,
-andrey
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem with glob qualifier e
2005-09-06 2:51 ` Andrey Borzenkov
@ 2005-09-06 13:58 ` Bart Schaefer
0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2005-09-06 13:58 UTC (permalink / raw)
To: zsh-users
On Sep 6, 6:51am, Andrey Borzenkov wrote:
} Subject: Re: Problem with glob qualifier e
}
}
} On Monday 05 September 2005 23:05, Bart Schaefer wrote:
} > }
} > } (I do not know why xargs here won't process arguments seperated by
} > } spaces, it should)
} >
} > I'm not sure what you mean? xargs never processes arguments separated
} > by spaces. It always wants newlines or NULs.
}
} then manual page is wrong:
Ah, hmm, yes, you're right, and I've misremembered.
What I was thinking of is how xargs normally batches up its arguments.
One of the oft-stated reasons for using
find . -whatever ... | xargs something
rather than
find . -whatever ... -exec something {} \;
is that the latter runs something once for every file, whereas the
former runs it fewer times on groups of files.
However, my statement was correct for the case of `xargs -i' because the
manual page goes on to say:
--replace[=replace-str], -i[replace-str]
Replace occurences of replace-str in the initial arguments with
names read from standard input. Also, unquoted blanks do not
terminate arguments. If replace-str is omitted, it defaults to
"{}" (like for `find -exec'). Implies -x and -l 1.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Problem with glob qualifier e
2005-09-05 16:32 Problem with glob qualifier e Hannu Koivisto
2005-09-05 17:22 ` Andrey Borzenkov
@ 2005-09-05 18:39 ` Bart Schaefer
1 sibling, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2005-09-05 18:39 UTC (permalink / raw)
To: Hannu Koivisto, Zsh Users' List
On Sep 5, 7:32pm, Hannu Koivisto wrote:
} Subject: Problem with glob qualifier e
}
} For instance, let's say that I would like to splice two command
} line arguments after each file argument produced by a glob pattern.
This was discussed at some length back in April, on a zsh-users thread
with subject "globbing with interposition".
See, for example, zsh-users/8702.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-09-06 13:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-05 16:32 Problem with glob qualifier e Hannu Koivisto
2005-09-05 17:22 ` Andrey Borzenkov
2005-09-05 19:05 ` Bart Schaefer
2005-09-06 2:51 ` Andrey Borzenkov
2005-09-06 13:58 ` Bart Schaefer
2005-09-05 18:39 ` 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).