title: How do I pass variable inside find and bash -c?
body: <p>I have issues with passing variable to %exe part of the code.</p>
  <p>Here is my working code that I use inside bash script:</p>
  <pre><code>## Function
  targz() {
    find $1 -type f -name &quot;*.$2&quot; -exec \
      bash -c 'old=$(basename {}); new=${old/%exe/tar\.gz}; \
        tar -zcvf $new $old; ' \;
  }
  
  ## Function Call
  ## targz [directory] [extension]
  targz . 'exe';
  </code></pre>
  <p>and yes I've tried using it some thing like this:</p>
  <pre><code>new=${old/%$2/tar\.gz};
  </code></pre>
  <p>but it generates filenames like: file.exetar.gz .</p>