- 怎麼辦替代合適?
你不能在你正在嘗試做的,因爲{}
不是一個bash變量(只xargs的語法的一部分)的方式使用替代,因此慶典不能做就可以替換。
給它一個更好的辦法是創建一個完整的bash命令,並提供它作爲和參數xargs的(例如xargs -0 -i bash -c 'echo cp "$1" "${1%.txt}.dat"' - '{}'
- 這種方式,您可以做慶典替換)。
- 我很好奇xargs會在for循環做一件事情的時候平行嗎?
是,for
循環會做認爲sequently但默認情況下xargs的總是會。但是,你可以使用的xargs
-P
選項並行化,從xargs
手冊頁:
-P max-procs, --max-procs=max-procs
Run up to max-procs processes at a time; the default is 1. If max-procs is 0, xargs will run as many processes as possible at a time. Use the -n option or the -L option
with -P; otherwise chances are that only one exec will be done. While xargs is running, you can send its process a
SIGUSR1信號同時增加指令的數量 運行,或SIGUSR2減少的數量。您不能將其增加到實現定義的限制以上( 以--show-limits顯示)。你不能在 以下將它折起。xargs永遠不會終止它的命令;當被要求減少時,它只是等待多於一個現有的 命令在啓動另一個命令之前終止。
Please note that it is up to the called processes to properly manage parallel access to shared resources. For example, if
其中超過一個嘗試打印到stdout, 的ouptut將在不確定的順序產生(而且很有可能混淆),除非流程,以防止一些這方面的 方式合作。使用某種鎖定方案是防止此類問題的一種方法。通常,使用鎖定方案將有助於確保正確的輸出,但會降低性能。如果您不想容忍性能差異,則只需安排每個進程生成一個單獨的輸出文件(或另外使用單獨的 資源)。