After some experimentation, this doesn't work:
ls | xargs -t -I {} {}/MyScript.sh param1 param2
But this does:
ls | xargs -t -I {} sh {}/MyScript.sh param1 param2
A close reading of the man page reveals why:
xargs [...] [command [initial-arguments]]
-I replace-str
Replace occurrences of replace-str in the initial-arguments
with names read from standard input.
If the {} is first, it is part of the command
, not the initial-arguments
, and thus is not replaced. So, you need to arrange things so that the {} is always part of the arguments, and not the command. In your case, this can easily be done by using sh {}/MyScript.sh
rather than invoking MyScript
directly.
(Note: I'm using bash here, where {}
with nothing inside it doesn't need to be quoted. Other shells may need to quote it.)