title: Loop over find result in bash
body: <p>I have a bash script written by some previous colleague in my company. It's shellcheck result is horrible and me, who is using zsh can't run the script. He seems to use the notorious find with for loop thingy in bash. But I can't figure out how to get it better.</p>
  <p>At the moment i got a temporary fix.</p>
  <p>this is his code</p>
  <pre><code>#!/bin/bash
  
    releases=$(for d in $(find ${DELIVERIES} -maxdepth 1 -type d -name &quot;*_delivery_33_SR*&quot; | sort) ; do echo ${d##*_} ; done)
    
    
    for sr in ${releases[@]}
    do
           echo &quot;Release $sr&quot;
           deliveries=$(find ${deliveries_path}/*${sr}/ -type f -name &quot;*.ear&quot; -o -name &quot;*.war&quot; | sort)
           if [ ! -e ${sr}.txt ]
           then
                   for d in ${deliveries[@]}
                   do
                           echo &quot;$(basename $d)&quot; | tee -a ${sr}.txt
                   done
           fi
           echo
    done
  </code></pre>
  <p>And this is my code that get to even loop the first part.</p>
  <pre><code>#!/bin/bash
                                                                                                                                                               
    for release in $(for d in $(find &quot;${DELIVERIES}&quot; -maxdepth 1 -type d -name &quot;*_delivery_33_SR*&quot; | sort) ; do echo &quot;${d##*_}&quot; ; done)
    do                                                                                                                                 
      echo &quot;Release $release&quot;                                   
    done
  </code></pre>
  <p>As you can see I needed to put the find inside the loop and I cant save it in an variable, because when i try to loop over it will try to put \n everywhere and it is like a single element? Could any1 suggest How should I solve this problem, because this previous colleague uses this kind of find search a lot.</p>
  <p>EDIT:</p>
  <p>The script went to each folder with a specific name and then created a file X.X.X.txt with the version number in the X part. And appended the filenames inside the subfolder to the X.X.X.txt</p>