title: how do I loop through the results of this FIND command in my Linux shell script?
body: <p>I wrote the following command to list all files in and below '~' by order of file size.  It seems to work fine:</p>
  
  <pre><code>find ~ -printf "%k KB %p\n" | sort -nr
  </code></pre>
  
  <p>Now I want to put this is a shell script and loop through the results to do more processing.</p>
  
  <p>I got this to work with a simple 'ls' command:</p>
  
  <pre><code>dir="/home/myusername"
  cmd='ls'
  for i in `$cmd`
  do
    echo $i
  done
  </code></pre>
  
  <p>But this doesn't work:</p>
  
  <pre><code>dir="/home/myusername"
  cmd='find $dir -printf "%k KB %p\n" | sort -nr'
  for i in `$cmd`
  do
    echo $i
  done
  </code></pre>
  
  <p>I've also tried using escape characters in front of the double-quotes, but that didn't work either ...</p>
  
  <pre><code>dir="/home/myusername"
  cmd='find $dir -printf \"%k KB %p\n\" | sort -nr'
  for i in `$cmd`
  do
    echo $i
  done
  </code></pre>
  
  <p>Any ideas what I'm doing wrong?</p>