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

Re: xargs with zsh function

On Mon, Jan 18, 2021 at 2:14 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> Playing with that running this script (test):
> $ . test
> xzargs: bad math expression: operator expected at `rap'

There's something in your test script you're not showing us; nothing in

xzargs() { zargs -t -- "${(f)$(read -d '' -E)}" -- "$@" }

would be evaluating a math expression.

> ... It works fine with a single literal input or a single string
> variable but I'd want to be throwing large numbers of lines at this.

The way xargs works is to gather up N lines until a "large enough"
argument list is assembled, and then call the command with those
arguments.  The way zargs works is to take all of those arguments on a
single command line and break them up into batches of N.

print -l "$vvar"  # this only prints one line, argument will be "mnt rap"
print -l $vvar    # This prints two lines, arguments will be "mnt" and "rap"

If you actually want to see this in action you need to specify that
zargs should only process one argument at a time.

% xzargs() { zargs -n 1 -t -- "${(f)$(read -d '' -E)}" -- "$@" }
% print -l $vvar | xzargs el
el mnt
el rap

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