Search code examples
bashgitxargs

XARGS Long Arguments and Pause Between Commands


Xargs will execute command more than once automatically if the command arguments are too long.

I am currently retrieving the revision differences in git and passing those arguments to git archive through xargs. It happens that the revision differences are long hence xargs automatically split the command into two times.

Because of that, git archive done twice for the same archive that leads to whatever being archived by the first command is wiped out by the second command.

Is there any way to let xargs pause between command or maybe notify xargs to archive into two different zip file?


Solution

  • You can have xargs run any command you like; that certainly can be a command that pauses or runs another trigger you define between invocations.

    So, if you're currently running:

    xargs -0 doSomethingWithFiles
    

    ...you can replace it with:

    xargs -0 bash -c '"$@"; sleep 5' _ doSomethingWithFiles