I'm using a command to rewrite files and I wanted to use it with makefile, but with makefile is not working, weird...
I exaplain all the problem, and the steps to solve it:
I have this structure:
/var/www/project/src/assets/img/magazines/<language>/<number>/01.jpg
/var/www/project/src/assets/img/magazines/<language>/<number>/02.jpg
/var/www/project/src/assets/img/magazines/<language>/<number>/03.jpg
...
But for new magazines, who uploads the pictures it has undesirable prefixes. REV56_ESP-30.jpg
. I have to remove all before the number of the set magazine pictures.
So I made this command to execute to shell.
find /var/www/project/src/assets/img/magazines/ -depth -exec rename -n 's/\/var\/www\/project\/src\/assets\/img\/magazines\/([a-z]+)\/([0-9]+).*-/\/var\/www\/project\/src\/assets\/img\/magazines\/$1\/$2\//' {} +
and it works so well.
Result:
rename(/var/www/project/src/assets/img/magazines/es/88/REV88_ESP-01.jpg, /var/www/project/src/assets/img/magazines/es/88/01.jpg)
rename(/var/www/project/src/assets/img/magazines/es/88/REV88_ESP-02.jpg, /var/www/project/src/assets/img/magazines/es/88/02.jpg)
So I was happy with this, but I wanted to add this command to makefile for using it easily.
Just that:
magazines-rename-script-dry:
find /var/www/project/src/assets/img/magazines/ -depth -exec rename -n 's/\/var\/www\/project\/src\/assets\/img\/magazines\/([a-z]+)\/([0-9]+).*-/\/var\/www\/project\/src\/assets\/img\/magazines\/$1\/$2\//' {} +
But when I run this rule:
root@server:/var/www/project# make magazines-rename-script-dry
find /var/www/project/src/assets/img/magazines/ -depth -exec rename -n 's/\/var\/www\/project\/src\/assets\/img\/magazines\/([a-z]+)\/([0-9]+).*-/\/var\/www\/project\/src\/assets\/img\/magazines\/\/\//' {} +
rename(/var/www/project/src/assets/img/magazines/es/82/REV82_ESP-26.jpg, /var/www/project/src/assets/img/magazines///26.jpg)
rename(/var/www/project/src/assets/img/magazines/es/82/REV82_ESP-12.jpg, /var/www/project/src/assets/img/magazines///12.jpg)
rename(/var/www/project/src/assets/img/magazines/es/82/REV82_ESP-14.jpg, /var/www/project/src/assets/img/magazines///14.jpg)
rename(/var/www/project/src/assets/img/magazines/es/82/REV82_ESP-35.jpg, /var/www/project/src/assets/img/magazines///35.jpg)
Why doesn't capture the number neither the language?
There is something wrong? I'm executing exactly the same line, why it has different results?
Prevent makefile expanding your $
s by dollar-escaping them:
magazines-rename-script-dry:
find /var/www/project/src/assets/img/magazines/ -depth -exec rename -n 's/\/var\/www\/project\/src\/assets\/img\/magazines\/([a-z]+)\/([0-9]+).*-/\/var\/www\/project\/src\/assets\/img\/magazines\/$$1\/$$2\//' {} +