[Ilugc] .a-tip-a-day. xargs command

  • From: kapil@xxxxxxxxxxx (Kapil Hari Paranjape)
  • Date: Tue Sep 22 09:01:48 2009

Hello,

On Tue, 22 Sep 2009, Roshan Mathews wrote:

This is interesting.

Indeed.

$ find -name "*.h" | xargs nano
Received SIGHUP or SIGTERM
<doesn't screw up anything, doesn't start>

$ find -name "*.h" | xargs emacs -nw
emacs: standard input is not a tty
<doesn't screw up anything, doesn't start>

$ find -name "*.h" | xargs vi
Vim: Warning: Input is not from a terminal
104 files to edit
<exit to find shell has gone to sleep>

The issue does seem to be, as Kapil Paranjape pointed out,
that vi has it's stdin set to /dev/null which it doesn't like.

It is not just "vi" the same happens to "emacs -nw" and "nano" which is
why the latter two exit. However, (like many unix commands) "vi"
assumes that you "know what you are doing" and starts up anyway,
whereas "emacs" and "nano" just quit since they "know what you mean".

$ find -name "*.h" | xargs emacs
<opens emacs with the files, everything ok>

$ find -name "*.h" | xargs gvim
104 files to edit
<works, exits, everything ok>

Since these are commands start a new window, they create a new
handler for input and so are not affected by setting stdin to
/dev/null.

Ideally, if one wants to use this method then a more appropriate
choice of command is "emacs-client" or whatever it is called
nowadays. This prevents yet another instance of emacs from being
started if one is already running.

Kapil.
--

Other related posts: