[comp.unix.questions] xargs

ok@quintus.UUCP (Richard A. O'Keefe) (02/12/88)

Having had rather more core-dumps from xargs(1) {on lots of different
machines} than I really care for, I decided that it was time to write
my own.  Deciding that the thing to do was to make it as exactly
compatible as I could, only working, I turned to the SVID to find out
just what xargs is supposed to do.  I find the XARGS(SD_CMD) section
of the SVID remarkably obscure.  For example, are empty lines to be
discarded in the sense that they aren't *counted* by the -l option,
or are they to be discarded only in the sense that they don't
contribute any arguments?  {Don't suggest running the program; what I
want to know is what it is *supposed* to do.}  If a line has a space
or tab before the new-line, is it still counted by -l?  What about
new-lines quoted by \ ?  We are told that blanks and tabs are allowed
in arguments, if quoted, but what about new-lines?

Then too, what is the significance of the magic numbers?
 -- why will "-i" accept only five *arguments* containing replstr,
    given that any one argument may contain any number of instances
    of replstr?  Would anything break if this limit were raised?
 -- why may constructed arguments grow to only 255 characters
    (apart from the fact that it crashes if you try a bigger number)?
    The exec() family is happy with much longer arguments than that!
    This is particularly painful in BSD systems, where a single
    file-name can be 1023 characters long...
 -- Why is the maximum total size of an argument list 470 characters?
    See above comment on file names.

The XARGS(SD_CMD) section also says that "xargs will terminate if ...
it receives a return code of -1 from ... command".  This is bizarre,
because elsewhere the SVID makes it clear that the exit status of a
command is ((W)>>8)&0377, where W is the result WAIT(BA_OS) gets.
Does the xargs section mean 255?  Or 1?  Or any non-zero value (which
would be consistent with everthing else)?

So, is there a clear description of xargs anywhere?

gwyn@brl-smoke.ARPA (Doug Gwyn ) (02/12/88)

In article <642@cresswell.quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes:
>So, is there a clear description of xargs anywhere?

IEEE 1003.2 recently had an "xargs" proposal, even though they left
it off the original command list (to my dismay; it or something
better like "apply" is an essential utility).  Since you're trying
to implement xargs from scratch, the 1003.2 spec (assuming it ends
up in the final standard) would be the one to track.

herb@hpindda.HP.COM (Herb Gellis) (02/17/88)

Oy veh!

As the original author of xargs, I will respond ...

I wrote xargs about 10 (TEN) years ago when I worked at Bell Labs in
Piscataway NJ. At that time the Bourne Shell didn't exist yet. The original
shell was relatively primitive, and was being greatly enhanced (by John Mashey).
There were lots of other "primitive" aspects of UNIX, such as sizes of things
(max of 512 bytes for file name expansions on the command line... later
changed to 5120 byes), etc. etc. This latter aspect of max 512 byte file
name expansion was the major reason I wrote xargs in the first place, and
then added -i, etc. as new features seemed useful.

The funny (small) sizes are merely choices made at the time, some reflecting
"real world" or "convenient" sizes FOR THE TIME (long ago, and far away...).
There were other silly reasons for some things... By using simple I/O
(avoiding printf, e.g.) xargs was kept at under the "magic" size of 4K
and was able to load very quickly (magic back then before sizes in the
file system were revamped). Obviously sizes should have been changed
as UNIX changed around it, but I doubt very much that xargs was ever enhanced
(I left B.T.L. in 1981)...

I also wrote the man page from which you speak (and I agree it is an abortion,
but I couldn't stand looking at it anymore either) and obviously it has never
changed either (the same man page is in our HP-UX). Oh well. Sorry about
those core dumps... I've never seen any.

To attempt to answer your questions specifically (based on whatever
design decisions I think I remember making mucho years ago):

>of the SVID remarkably obscure.  For example, are empty lines to be
>discarded in the sense that they aren't *counted* by the -l option,
>or are they to be discarded only in the sense that they don't
>contribute any arguments?  {Don't suggest running the program; what I

Both, don't count them for -l and discard them as they don't contribute.

>want to know is what it is *supposed* to do.}  If a line has a space
>or tab before the new-line, is it still counted by -l?  What about

No. This meant the line was continued to the next physical line
but was logically one line. (I realize that was a dumb way to do it,
should have used the \ escaped newline method)

>new-lines quoted by \ ?  We are told that blanks and tabs are allowed
           ^^^^^^^^^^^^^
>in arguments, if quoted, but what about new-lines?
                              ^^^^^^^^^^^^^^^^^^^^^
No on both counts.

> -- why will "-i" accept only five *arguments* containing replstr,
>    given that any one argument may contain any number of instances
>    of replstr?  Would anything break if this limit were raised?

Why 5? Because I wrote it that way. Don't remember if it was a static
array, but this is purely arbitrary, and could be changed at will.

>-- why may constructed arguments grow to only 255 characters

That's how big the (static) buffer was.

>The XARGS(SD_CMD) section also says that "xargs will terminate if ...
>it receives a return code of -1 from ... command".  This is bizarre,

Didn't seem unreasonable back in 1977 or thereabouts.

>So, is there a clear description of xargs anywhere?

No comment! (sorry)
Herb
 .                                  .
 |=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-| "What will I be when I grow up?
 | Herb Gellis                      | You are already grown up.
 | {ucbvax,...}!hplabs!hpindda!herb | You mean this is as UP as I will get?..."
 |=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-| 
 |                                  | David Gerrold, "When HARLIE Was One"
---                                ---

marc@pinet.aip.org (Marc Wiener) (04/13/91)

I'm trying to use xargs on a Dec 5000 running Ultrix 4.0. While the
following works, it also core dumps:

ls /usr/xy1/aip/bin | xargs -i -t cp /usr/xy1/aip/bin/\{} /tmp

I had the same problem with a System V.0 machine. Am I doing something
wrong?

marc
-- 
Marc Wiener                    |    marc@pinet.aip.org
American Institute of Physics  |    marc@aip.bitnet
500 Sunnyside Blvd.            |
Woodbury, NY 11797             |     (516)349-7800