patchfindutils - Patches: patch #4916, [PATCH] xargs -J (FreeBSD...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #4916: [PATCH] xargs -J (FreeBSD compatibility)

Submitter:  Robert Millan <robertmh>
Submitted:  Fri 17 Feb 2006 10:34:35 AM UTC
   
 
Category:  xargs enhancement Priority:  5 - Normal
Status:  None Privacy:  Public
Assigned to:  None Originator Name: 
Open/Closed:  Open Release:  None
Fixed Release:  None

Jump to the original submission

Sat 25 Jun 2011 10:13:26 PM UTC, comment #7: 

Sorry for the delay. Please consider the attachment, I looked at Andrea's points and implemented a patch that follows them.


(file #23561)

Robert Millan <robertmh>
Sun 29 Apr 2007 12:53:12 AM UTC, comment #6: 

Robert, could you respond to Andreas's points?

James Youngman <jay>
Group administrator
Sat 21 Apr 2007 04:47:24 PM UTC, comment #5: 

Hello,
I am not sure about the patch. (file #9590) Afaict it is supposed to make xargs act the same way for -J as for -I with a single difference: Replace only the first instance of replace-string.
----------------------
prompt$ printf 'bar fasel\n' | ./xargs -I % echo x % 1 % 2 %
x bar fasel 1 bar fasel 2 bar fasel
prompt$ printf 'bar fasel\n' | ./xargs -J % echo x % 1 % 2 %
x bar fasel 1 % 2 %
----------------------

However afaiui the FreeBSD manpage there are at least two other significant differences. "-I" changes xargs' behavior in multiple aspects:
#1 split only on line ends instead of also on space:
---------------------
ametzler@argenau:/tmp$ touch 'blah fasel'
ametzler@argenau:/tmp$ printf 'blah fasel\n' | xargs  -I % ls %
blah fasel
ametzler@argenau:/tmp$ printf 'blah fasel\n' | xargs  ls
ls: blah: No such file or directory
ls: fasel: No such file or directory
---------------------
#2 execute utility once for every line of input instead of making the commandline longer.

Afaiu the manpage "-J" is not supposed to make either of these two changes to xargs' default behavior, i.e. this should be the resulting behavior:
ametzler@argenau:/tmp$ printf 'blah fasel\nnonexist\n' | xargs -J % ls %
ls: blah: No such file or directory
ls: fasel: No such file or directory
ls: nonexist: No such file or directory
ametzler@argenau:/tmp$ printf 'blah fasel\nnonexist\n' | xargs -J % echo x %
x blah fasel nonexist

The above mentioned difference #1 between FreeBSD xargs and patched GNU-find causes different results, #2 only degraded performance.

On top of that the patch seems to be buggy with respect to multiline input. Only the first line of input is actually passed on:
ametzler@argenau:/tmp$ printf 'blah fasel\nnonexist\n' | /tmp/findutils-4.2.27/xargs/xargs -J % echo x %
x blah fasel
x %

Sorry for the delay in following up.

cu andreas
PS: I have not got access to a FreeBSD system to actually test its behavior, my only source of input is the online manpage.

Andreas Metzler <ametzler>
Sat 21 Apr 2007 02:00:03 PM UTC, comment #4: 

I would appreciate a response.

James Youngman <jay>
Group administrator
Sat 06 May 2006 07:22:02 AM UTC, comment #3: 

Hi!

Any news on this?  Does my second patch look fine?

Robert Millan <robertmh>
Mon 20 Feb 2006 09:31:56 AM UTC, comment #2: 

I didn't notice.  Please excuse me for my oversight.

Here's a patch that makes -J replace only the first instance.

Robert Millan <robertmh>
Sat 18 Feb 2006 08:54:05 AM UTC, comment #1: 

Afaict from http://www.freebsd.org/cgi/man.cgi?query=xargs&apropos=0&sektion=0&manpath=FreeBSD+6.0-RELEASE+and+Ports&format=html
and
http://www.openbsd.org/cgi-bin/man.cgi?query=xargs&apropos=0&sektion=0&manpath=OpenBSD+Current&arch=i386&format=html
-I and -J provide different functionality on *BSD (especially replacing all or only the first occurence of replstring), so this patch seems to be bogus.

---------------------------
     -I replstr
     Execute utility for each input line, replacing one or more occur-
     rences of replstr in up to replacements (or 5 if no -R flag is
     specified) arguments to utility with the entire line of input.
     The resulting arguments, after replacement is done, will not be
     allowed to grow beyond 255 bytes; this is implemented by concate-
     nating as much of the argument containing replstr as possible, to
     the constructed arguments to utility, up to 255 bytes.  The 255
     byte limit does not apply to arguments to utility which do not
     contain replstr, and furthermore, no replacement will be done on
     utility itself.  Implies -x.

     -J replstr
     If this option is specified, xargs will use the data read from
     standard input to replace the first occurrence of replstr instead
     of appending that data after all other arguments. This option
     will not affect how many arguments will be read from input (-n),
     or the size of the command(s) xargs will generate (-s).  The
     option just moves where those arguments will be placed in the
     command(s) that are executed.  The replstr must show up as a dis-
     tinct argument to xargs.  It will not be recognized if, for
     instance, it is in the middle of a quoted string. Furthermore,
     only the first occurrence of the replstr will be replaced.  For
     example, the following command will copy the list of files and
     directories which start with an uppercase letter in the current
     directory to destdir:

   /bin/ls -1d [A-Z]* | xargs -J % cp -rp % destdir
--------------------

Andreas Metzler <ametzler>
Fri 17 Feb 2006 10:34:35 AM UTC, original submission:  


Please could you add -J as an alias for -I ?  This is for compatibility with FreeBSD.

2006-02-17  Robert Millan  <robertmh@gnu.org>

        * xargs/xargs.c: Accept -J as an alias for -I, but do not document it,
        since this is just a FreeBSD compatibility extension.

diff -ur findutils-4.2.27.old/xargs/xargs.c findutils-4.2.27/xargs/xargs.c
--- findutils-4.2.27.old/xargs/xargs.c  2005-12-04 03:51:36.000000000 +0100
+++ findutils-4.2.27/xargs/xargs.c      2006-02-17 11:28:27.000000000 +0100
@@ -508,6 +508,7 @@
          return 0;

        case 'I':               /* POSIX */
+       case 'J':               /* FreeBSD compat */
        case 'i':               /* deprecated */
          if (optarg)
            bc_ctl.replace_pat = optarg;

Robert Millan <robertmh>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #23561:  xargs_J.diff added by robertmh (3KiB - text/plain)
file #9590:  xargs_J.diff added by robertmh (3KiB - text/plain)
file #9581:  xargs_J.diff added by robertmh (572B - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by robertmh (Updated the item)
  • -email is unavailable- added by ametzler
  • -email is unavailable- added by ametzler (Posted a comment)
  • -email is unavailable- added by jay (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-06-25 robertmh Attached File- Added xargs_J.diff, #23561
    2007-04-21 ametzler Carbon-Copy- Added -email is unavailable-
    2007-04-21 ametzler Carbon-CopyRemoved -email is unavailable- -
    2007-04-21 ametzler Carbon-Copy- Added -email is unavailable-
    2006-02-20 robertmh Attached File- Added xargs_J.diff, #5970
    2006-02-17 robertmh Attached File- Added xargs_J.diff, #5948
        Carbon-Copy- Added andreasmetzler<ametzler@debian.org>

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code