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

Re: Possible bug in zargs

On Oct 30, 12:05am, Dima Kogan wrote:
} Attached is a patch that fixes this. There was some misbehaving logic
} in the script. I don't understand why that logic was ever necessary.
} Does anybody know why the value of $n was connected to the value of $c
} at all?

Sorry, meant to reply to this thread earlier but I had an unusually busy
weekend.  Short answer:  The previous behavior was the intended behavior
and I'm going to recommend against accepting this patch.

$n represents the maximum number of arguments that may be passed to the
called command.  NOT the maximum number of arguments that may be taken
from the input list and added to the other arguments of the command, but
the maximum that may be passed to the command, period.

$c is the number of arguments of the command that appear outside of the
input list, that is, the number of arguments that trail the end of the
whole zargs construct.  In your example:

} > dima@shorty:/tmp$ zargs -n1 -- * -- ls -l
} > zargs: argument list too long

You've said that "ls" should be passed at most one argument (-n1).  That 
one argument is "-l".  Therefore there is no room to pass any of the
arguments from the input list (expansion of "*") without passing too
many arguments, so you get the error.

This may seem silly your example above, but it could be very important
if for example you're using a larger value of -n with some sort of
$(command) substitution generating the command for zargs to execute.

What you actually want in your example is this:

    zargs -l1 -- * -- ls -l

The manual page explains this:

     The options -i, -I, -l, -L, and -n differ slightly from their
     usage in xargs.  There are no input lines for zargs to count, so
     -l and -L count through the INPUT list, and -n counts the number
     of arguments passed to each execution of COMMAND, _including_ any
     ARG list.  Also, any time -i or -I is used, each INPUT is
     processed separately as if by `-L 1'.

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