Re: what should xargs do with empty stdin?
From: Todd Smith (tsmith_at_sgi.com)
Date: 01/03/04
- Previous message: Erik Max Francis: "Re: what should xargs do with empty stdin?"
- In reply to: Erik Max Francis: "Re: what should xargs do with empty stdin?"
- Next in thread: Erik Max Francis: "Re: what should xargs do with empty stdin?"
- Reply: Erik Max Francis: "Re: what should xargs do with empty stdin?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 2 Jan 2004 23:44:01 GMT
In article <3FF5E99C.BFD8D794@alcyone.com>, Erik Max Francis <max@alcyone.com> writes:
|> Todd Smith wrote:
|>
|> > Say I write a sequence of commands to remove all C source files under
|> > a particular root directory. If there happen not to be any such files
|> > there, I get the following (unnecessary and annoying) error:
|> >
|> > > find . -name "*.[ch]" -print | xargs rm
|> > Incorrect usage
|> > Usage: rm [-fir] file ...
|> ...
|> > Is this the intended behavior? Is there a portable way of avoiding
|> > this? On IRIX, I can use "xargs -L1", but the (GNU?) xargs on my
|> > Linux system doesn't like -L or seem to have anything equivalent.
|>
|> Look at the error: It's _rm_ reporting this complaint, not xargs. Your
|> question actually has nothing to do with xargs; it's how to get the
|> command that xargs is going to run to accept no arguments. With rm, add
|> the -f option.
I understand that it is _rm_ reporting the complaint, but I think its
complaint is justified.
Certainly this behavior of xargs violates the principle of least
surprise. If I ran the following in csh:
foreach i (*.[ch])
# loop body
end
in a directory with no C source files, I definitely wouldn't expect
the loop body to still be executed once, with no value for $i, even if
I could find some way (like adding a -f option to _rm_) to make it
work.
Some commands have different modes of operation, depending upon the
presence or absence of arguments. Some uses of xargs specify a
command *and* some initial arguments, to be followed by sets of
arguments added by xargs. I would rather have xargs behave
intuitively than have to go and ensure that each one of the
(unlimited) set of command possibilities I might use with it is able
to handle this boundary case gracefully.
In any case, another poster pointed me to an appropriate option for
GNU xargs, so at least I am able to get the behavior I wanted, if not
in the same way for every platform's default xargs implementation.
Todd Smith
- Previous message: Erik Max Francis: "Re: what should xargs do with empty stdin?"
- In reply to: Erik Max Francis: "Re: what should xargs do with empty stdin?"
- Next in thread: Erik Max Francis: "Re: what should xargs do with empty stdin?"
- Reply: Erik Max Francis: "Re: what should xargs do with empty stdin?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|