Bash variable substitution on find's output through exec

折月煮酒 提交于 2019-11-29 11:15:25

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/' {} +
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!