zsh-users
 help / color / mirror / code / Atom feed
* zargs: unexpected, non-xargs behaviour
@ 2012-05-07  8:41 Stephen Blott
  2012-05-07 14:14 ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Blott @ 2012-05-07  8:41 UTC (permalink / raw)
  To: zsh-users

Hi,

Consider this script:

# ----------------------------------------------------

   autoload -U zargs

   data=(foo bar)

   echo $data | xargs -n 1 echo XX
   zargs -n 1 -- $data -- =echo XX

# ----------------------------------------------------

I expected these to be equivalent, but here's the output:

   $ zsh < zargs_test.sh
   XX foo                                                                         
   XX bar                                                                         
   zargs: argument list too long                                                  
   zsh: exit 1     zsh < zargs_test.sh

To get zargs to work as intended (separate calls to echo for each
argument), I have use "-n 2".

So, at least for this example, when the documentation says "This function
works like GNU xargs, ...", that doesn't appear to be the case.

Am I missing something?

Steve



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: zargs: unexpected, non-xargs behaviour
  2012-05-07  8:41 zargs: unexpected, non-xargs behaviour Stephen Blott
@ 2012-05-07 14:14 ` Bart Schaefer
  2012-05-07 14:24   ` Moritz Bunkus
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2012-05-07 14:14 UTC (permalink / raw)
  To: zsh-users

On May 7,  9:41am, Stephen Blott wrote:
}
} Am I missing something?

In the comments in the zargs function file:

# * POSIX -L and -n are mutually exclusive and effectively synonymous;
#   zargs accepts both and considers -n to be a limit on the total number
#   of arguments per command line, that is, including the initial-args.
#   Thus the following fails with "argument list too long":
#     zargs -n 3 -- echo Here are four words
#   The smallest limit implied by the combination of -L and -n is used.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: zargs: unexpected, non-xargs behaviour
  2012-05-07 14:14 ` Bart Schaefer
@ 2012-05-07 14:24   ` Moritz Bunkus
  2012-05-07 14:26     ` Moritz Bunkus
  0 siblings, 1 reply; 7+ messages in thread
From: Moritz Bunkus @ 2012-05-07 14:24 UTC (permalink / raw)
  To: zsh-users

Hey,

On Mon, May 7, 2012 at 4:14 PM, Bart Schaefer <schaefer@brasslantern.com> wrote:

> In the comments in the zargs function file:

Well, then zargs is not POSIX compliant if I read
http://pubs.opengroup.org/onlinepubs/000095399/utilities/xargs.html
right as the POSIX documentation does not mention aborting if there
are more than "-n arg" arguments in total. On the contrary, it talks
about using fewer than "arg" if there are less _during the last
iteration_.

Kind regards,
mo


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: zargs: unexpected, non-xargs behaviour
  2012-05-07 14:24   ` Moritz Bunkus
@ 2012-05-07 14:26     ` Moritz Bunkus
  2012-05-07 15:25       ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Moritz Bunkus @ 2012-05-07 14:26 UTC (permalink / raw)
  To: zsh-users

Hey,

On Mon, May 7, 2012 at 4:24 PM, Moritz Bunkus <moritz@bunkus.org> wrote:

> Well, then zargs is not POSIX compliant...

...and also not equivalent to GNU xargs.

Also: In GNU xargs "-L" and "-n" have the very, very important
distinction that "-L" implies "-x" while "-n" does not (GNU xargs from
findutils 4.4.2).

Kind regards,
mo


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: zargs: unexpected, non-xargs behaviour
  2012-05-07 14:26     ` Moritz Bunkus
@ 2012-05-07 15:25       ` Bart Schaefer
  2012-05-07 16:10         ` Moritz Bunkus
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2012-05-07 15:25 UTC (permalink / raw)
  To: zsh-users

[Combining a couple of replies here.]

On May 7,  4:14 and 4:24pm, Moritz Bunkus wrote:
}
} Well, then zargs is not POSIX compliant
} ...and also not equivalent to GNU xargs.

Well, if you'll pardon the expression, duh.  The whole premise of zargs
is off the xargs rails because it doesn't read files or count lines.

} Also: In GNU xargs "-L" and "-n" have the very, very important
} distinction that "-L" implies "-x" while "-n" does not (GNU xargs from
} findutils 4.4.2).

The more important distinction is that in xargs -L and -n are counting
completely different things.  In zargs they're both counting the same
thing.  In fact neither -L nor -n implies -x in zargs (the exit in your
example has nothing to do with the -s option, and -x only applies when
the -s size is exceeded).

} if I read
} http://pubs.opengroup.org/onlinepubs/000095399/utilities/xargs.html
} right as the POSIX documentation does not mention aborting if there
} are more than "-n arg" arguments in total. On the contrary, it talks
} about using fewer than "arg" if there are less _during the last
} iteration_.

True, but again only sensible if "number of lines" and "number of args"
mean different things.  Because of the way zargs divides up the array
of arguments, there's no case in which it will ever do any useful work
if the contraints on -n are violated; would you have been less confused
if it did nothing and exited with success?


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: zargs: unexpected, non-xargs behaviour
  2012-05-07 15:25       ` Bart Schaefer
@ 2012-05-07 16:10         ` Moritz Bunkus
  2012-05-07 17:02           ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Moritz Bunkus @ 2012-05-07 16:10 UTC (permalink / raw)
  To: zsh-users

*sigh* The reply should have gone to the list. Sorry, my bad.

Hey,

On Mon, May 7, 2012 at 5:25 PM, Bart Schaefer <schaefer@brasslantern.com> wrote:

> } Well, then zargs is not POSIX compliant
> } ...and also not equivalent to GNU xargs.
>
> Well, if you'll pardon the expression, duh.  The whole premise of zargs
> is off the xargs rails because it doesn't read files or count lines.

I'm referring zsh's documentation:

[citation]
    This function works like GNU xargs, except that instead of reading
    lines of arguments from the standard input, it takes them from the
    command line.
[/citation]

For me as a user of zsh unfamiliar with its internals this has the
heavy implication that it works just like GNU xargs with a single
important difference. In reality it has a lot of similarities but
important differences in how arguments are counted and what happens if
limits are exceeded.

The documentation even closes with

[citation]
    For details of the other zargs options, see man page xargs(1) or
    run zargs with the --help option.
[/citation]

indicating once more that the options are supposed to work
identically. Which they simply don't. And that's what I find very
confusing.

A strong hint at the very beginning of the documentation that the
number of arguments are counted differently in GNU xargs and zargs
would probably help a lot. At least you could refer to the fact being
documented properly instead of having to argue with users like me ;)

Kind regards,
mo


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: zargs: unexpected, non-xargs behaviour
  2012-05-07 16:10         ` Moritz Bunkus
@ 2012-05-07 17:02           ` Bart Schaefer
  0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2012-05-07 17:02 UTC (permalink / raw)
  To: zsh-users

On May 7,  6:10pm, Moritz Bunkus wrote:
}
} A strong hint at the very beginning of the documentation that the
} number of arguments are counted differently in GNU xargs and zargs
} would probably help a lot.

Yes, the info / manpage doc for a lot of the contributed functions is
sparse.  We don't have any volunteers dedicated to this sort of thing
so they get updated piecemeal when (a) someone notices and (b) that
intersects with [usually another] someone having time to write doc.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-05-07 17:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-07  8:41 zargs: unexpected, non-xargs behaviour Stephen Blott
2012-05-07 14:14 ` Bart Schaefer
2012-05-07 14:24   ` Moritz Bunkus
2012-05-07 14:26     ` Moritz Bunkus
2012-05-07 15:25       ` Bart Schaefer
2012-05-07 16:10         ` Moritz Bunkus
2012-05-07 17:02           ` 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).