1

find コマンドの結果に基づいて ZIP を作成したいと考えています。ただし、zip コマンドに zip するコンテンツがない場合、エラーがスローされます。

find ${DIRECTORY_TO_SEARCH} -type f -mtime -7 | xargs zip "${ZIP_FILE}"

zip コマンドによってスローされるエラー コード: zip エラー: zip ファイルが見つからないか空の

ファイル数が 0 を超える場合にのみ ZIP が作成されるようにするにはどうすればよいですか?

ありがとう!

4

1 に答える 1

1

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.

例:

$ echo "" | xargs echo "foo"
foo
$

$ echo "" | xargs -r echo "foo"
$
于 2013-04-20T09:33:29.327 に答える