Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: xargs with zsh function
- X-seq: zsh-users 26390
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: xargs with zsh function
- Date: Sun, 17 Jan 2021 19:10:10 -0800
- Archived-at: <https://zsh.org/users/26390>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-01/CAH%2Bw%3D7YREDgH5WZvK4wpBt8GD21ic6vJBY_ZU6HCpAWjU79KYg%40mail.gmail.com>
- In-reply-to: <eee04aa4-394f-9e4b-1637-538059745b5c@eastlink.ca>
- List-id: <zsh-users.zsh.org>
- References: <eee04aa4-394f-9e4b-1637-538059745b5c@eastlink.ca>
On Sun, Jan 17, 2021 at 3:12 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> Can it be done?
The problem isn't the pipe, it's that xargs isn't zsh.
> How do we pipe into a function?
That's the wrong question. You're not piping into a function, you're
piping into a process (xargs) that turns its input lines into a set of
command-line arguments.
How about this:
$ autoload zargs
$ xzargs() { zargs -- "${(f)$(read -d '' -E)}" -- "$@" }
$ ... | xzargs my_function
That does use a lot of memory, reading the entire stdin and turning it
into a command line.
What you really want to do is write a nested shell loop that consumes
N lines, then runs my_function, then does that again until it runs out
of input; and pipe to that loop. There are a bunch of ways to do
that. E.g.:
... | while (true)
do
set --
for i in {1..10}
do
read $i || break
done
my_function "$@"
[[ $# -eq 10 ]] || break
done
Messages sorted by:
Reverse Date,
Date,
Thread,
Author