如果上一个命令没有返回任何内容,请不要调用xargs

Sud*_*dar 2 shell xargs

我有以下命令检查是否添加了任何新文件并自动调用svn add所有这些文件

svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2}' | xargs svn add
Run Code Online (Sandbox Code Playgroud)

但是当没有文件时,svn add会产生警告.

如何停止xargs调用上一个命令不会导致任何值?该解决方案需要与GNU和BSD(Mac OS X)版本一起使用xargs.

Ada*_*iss 9

如果您正在运行GNU版本,请使用xargs -r:

--no-run-if-empty  
-r
   If the standard input does not contain any nonblanks, do not run the command.
   Normally, the command is run once even if there is no input. This option
   is a GNU extension.

http://linux.die.net/man/1/xargs