Bash variable substitution on find's output through exec Bash variable substitution on find's output through exec bash bash

Bash variable substitution on find's output through exec


It took me a while to get the question. Basically you are asking if something like:

echo "${test.png%.png}"

could be used to get the word test.

The answer is no. The string manipulation operators starting with ${ are a subset of the parameter substitution operators. They work only on variables, not with string literals, meaning you need to store the string in a variable before. Like this:

img="test.png"echo "${img%.png}"

Just for travellers from Google, I would use rename for this particular task. (As the OP already mentioned in his question). The command could look like this:

find -name '*png' -execdir rename 's/\.png/_copy.png/' {} +