title: Bash: given a list of arguments separated by newline, how to pass all of them to another process?
body: <p>A little backstory, because maybe my approach is fundamentally wrong:</p>
  
  <p>Currently I'm trying to make a pre-commit script that checks what files where changed and passes them to a linter. Here's what I currently have:</p>
  
  <pre><code>STAGED=$(git diff --cached --name-only --diff-filter=ACM | grep -E "\.js$")
  echo "${STAGED}" | xargs -I {} eslint {}
  </code></pre>
  
  <p>This does work, but it has a flaw: it launches a new process for each file and, as you can imagine, the delay is noticeably large when given multiple files (and yes, launching this process on the whole folder manually doesn't take as long as launching it 20+ times on single files).</p>
  
  <p>I tried passing <code>-n $(echo ${STAGED} | wc -l)</code> to xargs, but that changed nothing.</p>
  
  <p>I also tried to do this:</p>
  
  <pre><code>eslint $(echo ${STAGED} | sed -E "s/^(.*)$/\"\1\"/g" | tr "\n" " ")
  </code></pre>
  
  <p>Quotes are there to make sure that files with whitespace are treated properly. But this did not work at all.</p>
  
  <p>Another thing I tried is changing <code>IFS</code>:</p>
  
  <pre><code>OLD_IFS="${IFS}"
  IFS=$'\n'
  eslint "${STAGED}"
  IFS="${OLD_IFS}"
  </code></pre>
  
  <p>That also did not work for me at all.</p>
  
  <p>Is there a decent solution to this problem?</p>