title: String concatenation in Bash script
body: <p>I am writing this Bash script:</p>
  
  <pre><code>count=0   
  result
  
  for d in `ls -1 $IMAGE_DIR | egrep "jpg$"`
  do
  
      if (( (count % 4) == 0 )); then
                  result="abc $d"
  
                  if (( count &gt; 0 )); then
                      echo "$result;"
                  fi
  
          else
              result="$result $d"
          fi
  
          (( count++ ))
  
  done
  
  if (( (count % 4) == 0 )); then
      echo $result
  fi
  </code></pre>
  
  <p>The script is to concate part strings into a string when the value is divided by 4 and it should be larger than 0.</p>
  
  <p>In the IMAGE_DIR, I have 8 images,</p>
  
  <p>I got outputs like this: </p>
  
  <pre><code>abc et004.jpg
  abc et008.jpg
  </code></pre>
  
  <p>But I would expect to have:</p>
  
  <pre><code>abc et001.jpg et002.jpg et003.jpg et004.jpg;
  abc et005.jpg et006.jpg et007.jpg et008.jpg;
  </code></pre>
  
  <p>How can I fix this?</p>