title: Using xargs to run bash scripts on multiple input lists with arguments
body: <p>I am trying to run a script on multiple lists of files while also passing arguments in parallel. I have file_list1.dat, file_list2.dat, file_list3.dat. I would like to run script.sh which accepts 3 arguments: arg1, arg2, arg3.</p>
  
  <p>For one run, I would do:</p>
  
  <pre><code>sh script.sh file_list1.dat $arg1 $arg2 $arg3
  </code></pre>
  
  <p>I would like to run this command in parallel for all the file lists.</p>
  
  <p>My attempt:</p>
  
  <pre><code>Ncores=4
  ls file_list*.dat | xargs -P "$Ncores" -n 1 [sh script.sh [$arg1 $arg2 $arg3]]
  </code></pre>
  
  <p>This results in the error: invalid number for -P option. I think the order of this command is wrong.</p>
  
  <p>My 2nd attempt: </p>
  
  <pre><code>echo $arg1 $arg2 $arg3 | xargs ls file_list*.dat | xargs -P "$Ncores" -n 1 sh script.sh
  </code></pre>
  
  <p>But this results in the error: xargs: ls: terminated by signal 13</p>
  
  <p>Any ideas on what the proper syntax is for passing arguments to a bash script with xargs?</p>