title: Shell script: for-loop within while loop
body: <p>I have 32 files (named by the same pattern, the only difference is the $sample number as written below) that I want to divide into 4 folders. I am trying to use the following script to do this job, but the script is not working, can someone help me with the following shell script please? - Thanks</p>
  
  <pre><code>#!/bin/bash
  
  max=8    #8 files in each sub folder
  numberFolder=4
  sample=0
  
  while ($numberFolder &gt; 1) #skip the current folder, as 8 files will remain
  do
    for (i=1; i&lt;9; i++)
    do
     $sample= $i * $numberFolder   # this distinguish one sample file from another
     echo "tophat_"$sample"_ACTTGA_L003_R1_001"  //just an echo test, if works, will replace it with "cp".
  
    done
  $numberFolder--
  end
  </code></pre>