xargs </dev/null behaviour

Stefan Bethke stb at lassitu.de
Thu Sep 1 09:49:37 GMT 2005

I've stumbled over the differing behavior of xargs when standard  
input delivers an immediate end of file:

In recent versions of FreeBSD and OpenBSD, I get this:

$ xargs echo foo </dev/null

On Solaris and Linux, I get this:

$ xargs echo foo </dev/null

Carefully reading the SUSv3 man page (the Solaris 10 one has very  
similar wordage), the Solaris/Linux behaviour seems to be correct:
> The xargs utility shall construct a command line consisting of the  
> utility and argument operands specified followed by as many  
> arguments read in sequence from standard input as fit in length and  
> number constraints specified by the options. The xargs utility  
> shall then invoke the constructed command line and wait for its  
> completion. This sequence shall be repeated [...]
I personally prefer the BSD behaviour, but I wonder whether anyone  
might rely on the SUSv3 behavior?

I came across a makefile that assumed BSD behavior, but failed:

     find . -name "*.orig" | xargs rm

because no orig files were found, but rm was executed anyway, with  
zero arguments.


Stefan Bethke <stb at lassitu.de>   Fon +49 170 346 0140

More information about the freebsd-standards mailing list