zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Dima Kogan <zsh@dima.secretsauce.net>, zsh-workers@zsh.org
Subject: Re: Possible bug in zargs
Date: Tue, 30 Oct 2012 09:09:09 -0700	[thread overview]
Message-ID: <121030090909.ZM7599@torch.brasslantern.com> (raw)
In-Reply-To: <20121030000536.260d4c15@shorty.local>

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'.


  reply	other threads:[~2012-10-30 16:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-27 22:34 Dima Kogan
2012-10-30  7:05 ` Dima Kogan
2012-10-30 16:09   ` Bart Schaefer [this message]
2012-10-30 17:53     ` Dima Kogan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=121030090909.ZM7599@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    --cc=zsh@dima.secretsauce.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).