我几乎已经完成了这段代码:
for PHOTO in /home/dvms/Desktop/projs/others/tests/gulp_test/src/images/*.{png,jpeg,jpg}
do
BASE=`basename $PHOTO`
convert "$PHOTO" -quality 50% "/home/dvms/Desktop/projs/others/tests/gulp_test/src/imagesCompressed/$BASE.jpg"
done
但是输出文件的旧文件扩展名仍在,并且在末尾附加“.jpg”,例如:imageA.png.jpg。
如何解决此问题?
答案1
将您的代码修改为以下形式:
for PHOTO in /home/dvms/Desktop/projs/others/tests/gulp_test/src/images/*.{png,jpeg,jpg}
do
BASE=$(basename $PHOTO)
convert "$PHOTO" -quality 50% "/home/dvms/Desktop/projs/others/tests/gulp_test/src/imagesCompressed/${BASE%.*}.jpg"
done
而不是这样$BASE.jpg
使用${BASE%.*}
然后添加扩展。
答案2
替换以下行:
BASE=`basename $PHOTO`
有了这个:
BASE=`basename $PHOTO | cut -d. -f1`
然后重试。