[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why xargs still call the command when there is no input?
From: |
Peng Yu |
Subject: |
Re: Why xargs still call the command when there is no input? |
Date: |
Tue, 2 Jun 2015 19:49:04 -0500 |
On Tue, Jun 2, 2015 at 5:50 PM, Morgan Weetman <address@hidden> wrote:
>
> Hi Peng,
>
> if you read the man page the behaviour is defined (note the "one or more
> times"):
>
> ---------------------
> xargs reads items
> from the standard input, delimited by blanks (which can be protected
> with double or single quotes or a backslash) or newlines, and executes
> the command (default is /bin/echo) one or more times with any initial-
> arguments followed by items read from standard input
> ---------------------
>
> So basically your command below will call 'ls' once with no arguments and
> display the contents of the current directory
But wouldn't be better to make this zero more times? Consider the
following example, intuitively, one just want to use ls to display all
the files. When there are no files, a nature choice is to display
nothing. However, this definition of xargs calls ls once which will
display all the files in the current directory. I think that this
default behavior is not very reasonable, I'd expect at least there
should be an option to disable it.
find -type f | xargs ls
--
Regards,
Peng