Makefile 重写文件不捕获正则表达式
Makefile rewriting files not capturing regular expressions
我正在使用重写文件的命令,我想将它与 makefile 一起使用,但是 makefile 无法正常工作,很奇怪...
我解释了所有问题,以及解决问题的步骤:
我有这样的结构:
/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
...
但是对于新杂志来说,谁上传的图片有不受欢迎的前缀。 REV56_ESP-30.jpg
。我要把设置的杂志图片号前的都去掉
所以我让这个命令执行到 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\/\/\//' {} +
而且效果很好。
结果:
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)
所以我对此很满意,但我想将此命令添加到 makefile 中以便于使用它。
就是这样:
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\/\/\//' {} +
但是当我运行这条规则时:
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)
为什么不抓取数字和语言?
有什么问题吗?我正在执行完全相同的行,为什么它有不同的结果?
防止 makefile 通过美元转义来扩展您的 $
s:
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\/$\/$\//' {} +
我正在使用重写文件的命令,我想将它与 makefile 一起使用,但是 makefile 无法正常工作,很奇怪...
我解释了所有问题,以及解决问题的步骤:
我有这样的结构:
/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
...
但是对于新杂志来说,谁上传的图片有不受欢迎的前缀。 REV56_ESP-30.jpg
。我要把设置的杂志图片号前的都去掉
所以我让这个命令执行到 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\/\/\//' {} +
而且效果很好。
结果:
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)
所以我对此很满意,但我想将此命令添加到 makefile 中以便于使用它。
就是这样:
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\/\/\//' {} +
但是当我运行这条规则时:
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)
为什么不抓取数字和语言?
有什么问题吗?我正在执行完全相同的行,为什么它有不同的结果?
防止 makefile 通过美元转义来扩展您的 $
s:
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\/$\/$\//' {} +