title: Pass all elements in existing array to xargs
body: <p>I am trying to pass an array of file paths to <code>xargs</code> to move them all to a new location. My script is currently working as follows:</p>
  
  <pre><code>FILES=( /path/to/files/*identifier* )
  if [ -f ${FILES[0]} ]
    then
      mv ${FILES[@]} /path/to/destination
  fi
  </code></pre>
  
  <p>The reason for having FILES as a array was because the <code>if [ -f /path/to/files/*identifier* ]</code> fails if the wildcard search returns multiple files. Only the first file is checked, because the move will be executed if any files exist.</p>
  
  <p>I want to replace <code>mv ${FILES[@]} /path/to/destination</code> with a line that passes <code>${FILES[@]}</code> to <code>xargs</code> to move each file. I need to use <code>xargs</code> as I expect to have enough files to overload a single <code>mv</code>. Through research I have only been able to find the methods of moving files that I already know which search for the files again.</p>
  
  <pre><code>#Method 1
  ls /path/to/files/*identifier* | xargs -i mv '{}' /path/to/destination
  
  #Method 2
  find /path/to/files/*identifier* | xargs -i mv '{}' /path/to/destination
  </code></pre>
  
  <h3>Is there a way to can pass all elements in an existing array <code>${FILES[@]}</code> to <code>xargs</code>?</h3>
  
  <p>Below are methods I've tried and their errors.</p>
  
  <p><strong>Attempt 1</strong>:</p>
  
  <pre><code>echo ${FILES[@]} | xargs -i mv '{}' /path/to/destination
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>mv: cannot stat `/path/to/files/file1.zip /path/to/files/file2.zip /path/to/files/file3.zip /path/to/files/file4.zip': No such file or directory
  </code></pre>
  
  <p><strong>Attempt 2</strong>:
  I wasn't sure if <code>xargs</code> can be executed directly or not.</p>
  
  <pre><code>xargs -i mv ${FILES[@]} /path/to/destination
  </code></pre>
  
  <p>Error:
  No error message was output, but it hung after that line until I stopped it manually.</p>
  
  <h2>Edit: Find works</h2>
  
  <p>I tried the following and it moved all the files. Is this the best way to do it? And is it moving the files one by one, so the terminal is not overloaded?</p>
  
  <pre><code>find ${FILES[@]} | xargs -i mv '{}' /path/to/destination
  </code></pre>
  
  <h2>Edit 2:</h2>
  
  <p>For future reference, I tested the accepted answer method versus the method in my first edit using <code>time()</code>. After running both methods 4 times, my method had an average of 0.659s and the accepted answer was 0.667s. So neither method works any faster than the other.</p>