Due to some reasons, the option order is important to the command. For example, different options order may cause different actions in ffmpeg, so where does xargs add the option from stdin?

For example:

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

is totally equivalent to:

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

but if I want to send input.avi from echo to xargs ffmpeg -i -r 24 output.avi by pipe, how do I set the string from STDIN to a specified position?

  • 1
    Please give an example of the command you're running. – terdon Nov 17 '14 at 2:48
  • There is no example (so far). I'm just curious how xargs perform. – Kevin Dong Nov 17 '14 at 2:52
  • OK, but I'm not sure where STDIN comes in. Anyway, xargs puts the arguments exactly where you tell it to. It would be easier to understand what you're asking if you could give an example where you think the arguments could be added in different places. – terdon Nov 17 '14 at 2:53
  • I added an example. – Kevin Dong Nov 17 '14 at 3:08

I'm not entirely sure I follow you but if you're asking how you can control where xargs places the arguments when passed to it, you can use the switch -I{} to denote what macro you want to use for input that's pasted to xargs and then make use of this macro where ever you want to have the things passed to xargs expanded.

NOTE: I'm using the notation {} for my macro I then simply put that macro where ever I want the arguments expanded.


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

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

$ echo hi | xargs -I{} echo {} {} bye
hi hi bye
excerpt from xargs man page
   -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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.