bugfindutils - Bugs: bug #51220, [wishlist] Using -I with -n

 
 

bug #51220: [wishlist] Using -I with -n

Submitted by:  Adam Danischewski <adanisch>
Submitted on:  Sun 11 Jun 2017 02:14:25 AM UTC  
 
Category: xargsSeverity: 3 - Normal
Item Group: NoneStatus: Working as Intended
Privacy: PublicAssigned to: Bernhard Voelker <berny>
Originator Name: Open/Closed: Closed
Release: NoneFixed Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Mon 12 Jun 2017 05:58:04 AM UTC, comment #6:

I did not expect such enthusiastic feedback.
I read it as "works for me", so I'm hereby closing this issue.

Bernhard Voelker <berny>
Project MemberIn charge of this item.
Mon 12 Jun 2017 01:11:40 AM UTC, comment #5:

[[spam content redacted]]

Anonymous
Mon 12 Jun 2017 01:09:51 AM UTC, comment #4:

[[spam content redacted]]

Anonymous
Sun 11 Jun 2017 08:09:45 PM UTC, comment #3:

The -I option already implies "-n 1" ... but - as POSIX [1]
says - the input is treated to be separated by newlines instead
of blanks.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/xargs.html

-I replstr
[XSI] [Option Start] Insert mode: utility is executed for each
logical line from standard input. Arguments in the standard input
shall be separated only by unescaped <newline> characters, not
by <blank> characters. [...]

That's exactly what GNU xargs does; example:

$ printf "%s\n" one two three four \
| xargs -I{} echo cp -v "/tmp/{}" /tmp/test
cp -v /tmp/one /tmp/test
cp -v /tmp/two /tmp/test
cp -v /tmp/three /tmp/test
cp -v /tmp/four /tmp/test

I think it's documented well enough both in GNU xarg's man page
and (similarly) in the Texinfo manual:

-I replace-str
[...] Also, unquoted blanks do not terminate input items;
instead the separator is the newline character. [...]

This is only missing for brevity in 'xargs --help' output.

Therefore, this is not a bug in the software, and implementing the
wish would clearly contradict to POSIX and break existing scripts.
Thus, I think I'll mark this as INVALID soon.

BTW: if you're sure to have GNU cp, then you could avoid the -I option
in the above example by using cp's --target option:

$ echo some files | xargs cp -vt /tmp/test

Have a nice day,
Berny

Bernhard Voelker <berny>
Project MemberIn charge of this item.
Sun 11 Jun 2017 01:29:52 PM UTC, comment #2:

The example doesn't seem to show that -I is incompatible with -n. Indeed 'one two three four' isn't split into four arguments, but the documentation for -I says that it won't:

-I replace-str
Replace occurrences of replace-str in the initial-arguments with
names read from standard input. Also, unquoted blanks do not
terminate input items; instead the separator is the newline
character. Implies -x and -L 1.

Dale Worley <worley>
Sun 11 Jun 2017 01:24:18 PM UTC, comment #1:

It would help if you simplified the example. In this case, make the variable substitutions. And instead of using "cp" as the command which is executed, thus showing us only the error message "cp" reports and leaving us to guess what the command was, use "echo" as the command.

That would give an example like this:
echo "one two three four" |
xargs -n1 -I{} echo cp -v "/tmp/{}" /tmp/test

Dale Worley <worley>
Sun 11 Jun 2017 02:14:25 AM UTC, original submission:

It would be nice if you could use -I substitution option with -n count option together in the same command.

E.g.
$> var=/tmp && echo "one two three four" | xargs -n1 touch "${var}/{}"

$> var=/tmp/test && mkdir -p "${var}" && echo "one two three four" | xargs -n1 | xargs -I{} cp -v "/tmp/{}" "${var}"
‘/tmp/one’ -> ‘/tmp/test/one’
‘/tmp/two’ -> ‘/tmp/test/two’
‘/tmp/three’ -> ‘/tmp/test/three’
‘/tmp/four’ -> ‘/tmp/test/four’

Yet it would be nice if instead, we could:
$> var=/tmp/test && mkdir -p "${var}" && echo "one two three four" |xargs -n1 -I{} cp -v "/tmp/{}" "${var}"
cp: cannot stat ‘/tmp/one two three four’: No such file or directory

Unfortunately we can't combine -n and -I substitution at the moment and I'm not sure why not. It could be useful.

Adam Danischewski <adanisch>

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by berny (Posted a comment)
  • -unavailable- added by worley (Posted a comment)
  • -unavailable- added by adanisch (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 12 Jun 2017 05:58:04 AM UTCbernyStatusNone=>Working as Intended
      Open/ClosedOpen=>Closed
    Sun 11 Jun 2017 08:09:45 PM UTCbernyCategoryNone=>xargs
      Assigned toNone=>berny

    Back to the top


    Powered by Savane 3.1-cleanup1