bugfindutils - Bugs: bug #51151, [wishlist] xargs -o support for...

 
 

bug #51151: [wishlist] xargs -o support for interactive commands

Submitted by:  Andreas Metzler <ametzler>
Submitted on:  Wed 31 May 2017 05:37:17 PM UTC  
Votes:  1  
 
Category:  xargs Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  Bernhard Voelker <berny>
Originator Name:  Open/Closed:  Open
Release:  4.6.0 Fixed 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)

Sun 23 Jul 2017 09:55:53 PM UTC, comment #13:

James, can you remember to type that?

I consider myself good in shell (after all, I maintain one), and still it took three times to type that from memory right, and that was after reading in the GNU documentation to use this form.

Plus there’s prior art in the BSDs, and adding this for compatibility and easiness doesn’t hurt anyone.

Thorsten Glaser <mirabilos>
Sun 23 Jul 2017 08:42:50 PM UTC, comment #12:

I've read the discussion but I don't understand what's wrong with this approach:

git grep -l -z foo | xargs -0 sh -c 'jupp "$@" < /dev/tty' jupp

This doesn't need "xargs -o" and is not specific to any shell implementation. There is talk in this bug report about problems with "sh -c ... --" but that construct ("--") is not used or needed.

So, can someone please explain what's wrong with "</dev/tty"?

James Youngman <jay>
Project Administrator
Thu 08 Jun 2017 10:49:31 PM UTC, comment #11:

Pushed:

  • [PATCH 2/2] doc: drop workarounds for missing xargs -o option

http://git.sv.gnu.org/cgit/findutils.git/commit/?id=3e4bb112ae

  • [PATCH 1/2] xargs: add -o, --open-tty option

http://git.sv.gnu.org/cgit/findutils.git/commit/?id=40cd25147b

Bernhard Voelker <berny>
Project AdministratorIn charge of this item.
Tue 06 Jun 2017 08:35:25 PM UTC, comment #10:

I agree with Andreas: the findutils manpages are too detailed IMO;
and it is a GNU recommendation to keep the man pages terse,
and to have the detailed documentation in Texinfo format (which may
be converted in other available formats like html, ps, pdf, etc.)
https://www.gnu.org/prep/standards/html_node/Man-Pages.html

Therefore, I'd favor to remove both these special shell redirection
example and the messy-to-the-eyes options list at the top of xargs.1
while keeping both in the Texinfo manual. There, I'd like to expand
a bit more about portability of -o vs shell redirection.

The attached is the v2 version which does the above little amendment,
plus adds a more detailed commit message for Andreas' patch.
Thanks for that BTW.

(file #40867)

Bernhard Voelker <berny>
Project AdministratorIn charge of this item.
Tue 06 Jun 2017 05:20:33 PM UTC, comment #9:

On 2017-06-06 Thorsten Glaser <INVALID.NOREPLY@gnu.org> wrote:

> 3. In Andreas’ patch, obviously, do not remove the </dev/tty example but
> reword it slightly.


> Rationale for #2 and #3: while the BSD extension is added, documenting this is
> likely still good for when one searches the documentation for information on
> how to achieve the same effect with either older GNU xargs or non-BSD/GNU
> xargs (modulo the problems I stated e.g. wrt. ‘--’).


FWIW I disagree here, the tradeoff seems wrong to me. The documentation needs to stay as short as possible, describing the most effective way.

If people do not know about "man xargs" filling up the manpage of GNU xargs with information that is not really relevant for the respective version GNU xargs in the hope that it find its way into google via man2www is just not efficient.

Andreas Metzler <ametzler>
Tue 06 Jun 2017 11:40:01 AM UTC, comment #8:

Hi Bernhard and Andreas,

thanks, but I’d change a few minor things:

1. Do not remove the list of all options at the top, it really helps one to get a quick overview and the specific spelling if one only vaguely remembers the correct option but gets it upon seeing it.

2. ↓

+The \-o option is an extension to the POSIX standard for better
+compatibility with BSD.

I’d change that into:

+compatibility with BSD. See below for an example of how to achieve this portably.

3. In Andreas’ patch, obviously, do not remove the </dev/tty example but reword it slightly.

Rationale for #2 and #3: while the BSD extension is added, documenting this is likely still good for when one searches the documentation for information on how to achieve the same effect with either older GNU xargs or non-BSD/GNU xargs (modulo the problems I stated e.g. wrt. ‘--’).

Thorsten Glaser <mirabilos>
Mon 05 Jun 2017 01:20:13 PM UTC, comment #7:

Hello Bernhard,
I think some more changes to the documentation would be a good thing. There are a couple of examples on how to jump through hoops because -o was not available. Suggested patchlet (to go on top of yours) included.
Andreas

(file #40852)

Andreas Metzler <ametzler>
Sun 04 Jun 2017 07:02:16 PM UTC, comment #6:

I agree. Patch attached; please review.
Any suggestions how to add tests for this?

Thanks & have a nice day,
Berny

(file #40851)

Bernhard Voelker <berny>
Project AdministratorIn charge of this item.
Sat 03 Jun 2017 10:52:22 PM UTC, comment #5:

All these workarounds may be nice, but…

$ git grep -l -z foo | xargs -o0 jupp

… is much easier to type and does not require using GNU bash as interactive shell,
and does already work on the BSDs.

That’s not to say the other options should not implemented, but please just a BSD-compatible ‘-o’ first. Thanks.

Thorsten Glaser <mirabilos>
Sat 03 Jun 2017 01:31:21 AM UTC, comment #4:

I suppose we could define

-Rn, --redirect-from=n

Redirect stdin for each executed command from fd n.

We could also do redirection from a file, and the user could use /dev/fd/n, etc.

Dale Worley <worley>
Fri 02 Jun 2017 12:06:15 AM UTC, comment #3:

I suggest this form as a workaround, particularly because it causes Emacs to see as stdin whatever the stdin in effect in the environment. I'm not sure there's a way that we could package that into an option for xargs, though.

exec 3<&0
find ... | xargs sh -c 'emacs "$@" <&3'
exec 3<&-

Dale Worley <worley>
Thu 01 Jun 2017 06:20:06 PM UTC, comment #2:

On 2017-06-01 Bernhard Voelker <INVALID.NOREPLY@gnu.org> wrote:

> isn't

[...]

> $ xargs -0n1 -a <(find -type f -print0) vi


> what you are looking for?

[...]

Afaict it fullfills the same purpose. However it requires using a specific shell (bash).

Andreas Metzler <ametzler>
Thu 01 Jun 2017 05:08:41 PM UTC, comment #1:

I'm not sure if I understand the requirement correctly,
but isn't

$ xargs -n1 -a <(ls) vi

or (for file names with unusual characters)

$ xargs -0n1 -a <(find -type f -print0) vi

what you are looking for?

Bernhard Voelker <berny>
Project AdministratorIn charge of this item.
Wed 31 May 2017 05:37:17 PM UTC, original submission:

Report by Thorsten Glaser in https://bugs.debian.org/725392:
The manual page of GNU xargs mentions this:

xargs sh -c 'emacs "$@" < /dev/tty' emacs

Launches the minimum number of copies of Emacs needed, one after the
other, to edit the files listed on xargs' standard input. This example
achieves the same effect as BSD's -o option, but in a more flexible and
portable way.

BSD’s ‘-o’ option is documented thus:

-o Reopen stdin as /dev/tty in the child process before executing
the command. This is useful if you want xargs to run an interac-
tive application.

IMHO, the -o option is much less cumbersome to type/remember, and for
the sake of reverse portability (support applications that already
use the BSD variant), and especially given that the GNU maintainers
already know of it, the -o option ought to be added to GNU xargs as
well.

Side effect: avoids launching another shell, and, more importantly
to some, avoids quoting hell.

(That being said, /bin/sh on FreeBSD and derivates thereof has
slightly broken (for hysterical raisins) behaviour when sh -c cmd
is followed by “--” so the portability the GNU maintainers assert
for the sh variant is not exactly true either.)
-------------------------------------------------

That said I (Andreas) am little bit of two minds on this. The issue has come up before in https://bugs.debian.org/5956
| Consider the following command:
|
| echo bar | (echo foo | xargs --interactive grep)
|
| What should grep's stdin be, /dev/tty or the stdout of "echo
| bar"? Is the answer different for other programs? Why? (I
| won't give my answers; the point is that reasonable people give
| different answers to these questions. Some of the preferred
| answers aren't even doable.)
|
| Mixing batch mode and interactive tools tends to cause problems.
| This situation is one of them. Not giving any stdin is about the
| best you can do, since it gives the least amount of surprises
| by not giving the wrong answer half the time.
|
| However, a new option to xargs that makes xargs read the
| filenames from some other file than stdin, giving stdin to the
| program being run, would be a good thing.

It was the resolved with this change:
| * New upstream version
| - New option --arg-file=file and extended documentation about
| stdin-handling (short in manpage, more extensive in info).
| (Closes: #5956)

Andreas Metzler <ametzler>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #40867:  [PATCH v2] xargs: add --open-tty option.patch added by berny (12KiB - text/x-patch - [PATCH v2] xargs: add --open-tty option.patch)
file #40852:  0001-doc-drop-workarounds-for-missing-xargs-o-option.patch added by ametzler (2KiB - text/x-diff - doc updates for xargs -o)
file #40851:  0001-xargs-add-o-open-tty-option.patch added by berny (9KiB - text/x-patch - [PATCH] xargs: add -o, --open-tty option)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jay (Posted a comment)
  • -email is unavailable- added by mirabilos (Posted a comment)
  • -email is unavailable- added by mirabilos
  • -email is unavailable- added by worley (Posted a comment)
  • -email is unavailable- added by berny (Posted a comment)
  • -email is unavailable- added by ametzler (Submitted the item)
  •  

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

    Only logged-in users can vote.

     

     

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-06-08 berny StatusCode Review => Fixed
    2017-06-06 berny Attached File- => Added [PATCH v2] xargs: add --open-tty option.patch, #40867
    2017-06-05 ametzler Attached File- => Added 0001-doc-drop-workarounds-for-missing-xargs-o-option.patch, #40852
    2017-06-04 berny Attached File- => Added 0001-xargs-add-o-open-tty-option.patch, #40851
        StatusNone => Code Review
        Assigned toNone => berny
    2017-06-03 mirabilos Carbon-Copy- => Added mirabilos

    Back to the top


    Powered by Savane 3.3