title: Bash variable substitution on find's output through exec
body: <p>Is there any way to apply <a href="https://tldp.org/LDP/abs/html/parameter-substitution.html" rel="nofollow noreferrer">Bash variable substitution</a> on <code>find</code>'s output? I know I've seen someone do it on Stack Overflow but I can't seem to find that particular post anymore.</p>
  <p><strong>As an example</strong>, let's say I want to rename files ending in <code>*.png</code> to <code>*_copy.png</code>. I know I can do this using <code>rename</code> but it's just a thought experiment.</p>
  <p>Now I'd like to be able to do something like this:</p>
  <pre><code>find . -name &quot;*png&quot; -exec mv &quot;{}&quot; &quot;${{}%.*}_copy.png&quot; \;
  </code></pre>
  <p>Which results in an <em>invalid substitution</em>. Of course, I could first assign the output to a variable and then apply substitution in a sub-shell, but <strong>is this really the only way?</strong></p>
  <pre><code>find . -name &quot;*.png&quot; -exec bash -c 'var=&quot;{}&quot;;  mv &quot;{}&quot; &quot;${var%.*}_copy.png&quot;' \;
  </code></pre>
  <p>Or <strong>is there any way this can be achieved directly from <code>{}</code>?</strong></p>
  <p><strong>Consensus</strong></p>
  <p>As <em>Etan Reisner</em> remarked, a better and safer way to handle the output of <code>find</code> would be to pass it as a positional argument:</p>
  <pre><code>find . -name &quot;*.png&quot; -exec bash -c 'mv &quot;$0&quot; &quot;${0%.*}_copy.png&quot;' &quot;{}&quot; \;
  </code></pre>