`xargs` 在哪裡新增來自 STDIN 的選項?

`xargs` 在哪裡新增來自 STDIN 的選項?

由於某些原因,選項順序對於命令來說很重要。例如,不同的選項順序可能會導致 中的操作不同ffmpeg,那麼xargs從哪裡新增選項呢stdin

例如:

$ echo 'output.avi' | xargs ffmpeg -i input.avi -r 24

完全等同於:

$ ffmpeg -i inpit.avi -r 24 output.avi

但是如果我想透過管道input.avi從發送echoxargs ffmpeg -i -r 24 output.avi,如何將 STDIN 中的字串設定到指定位置?

答案1

我不完全確定我明白你的意思,但如果你問如何控制傳遞xargs給它的參數的放置位置,你可以使用開關-I{}來表示要用於粘貼的輸入的宏xargs,然後使用這個宏的任何地方你想要將東西傳遞到xargs擴充。

筆記:我使用巨集的符號{},然後簡單地將巨集放在我想要擴展參數的位置。

例子

$ echo hi | xargs -I{} echo {}
hi

$ echo hi | xargs -I{} echo {} {}
hi hi

$ echo hi | xargs -I{} echo {} {} bye
hi hi bye
摘自 xargs 手冊頁
   -I replace-str
      Replace  occurrences of replace-str in the initial-arguments with 
      names read from standard input.  Also, unquoted blanks do not 
      terminate input items; instead the separator is the newline 
      character.  Implies -x and -L 1.

相關內容