【发布时间】:2011-04-27 10:21:54
【问题描述】:
我正在尝试编写将大照片裁剪并调整为高清壁纸的脚本。
#! /bin/bash
for i in `ls *.jpg`
do
width=`identify -format '%w' $i`
height=`identify -format '%h' $i`
if [ `echo "$width/$height > 16/9" | bc -l` ]
then
exec `convert $i -resize 1920 -gravity Center -crop '1920x1080+0+0' +repage temp`
else
exec `convert $i -resize x1080 -gravity Center -crop 1920x1080+0+0 +repage temp`
fi
rm $i
mv temp $i
done
但似乎该脚本在文件名中有空格(如 Tumble Weed.jpg)方面存在问题。我该如何解决这个问题?
【问题讨论】:
-
答案已经在下面给出了,但我想补充一点,shell 脚本对于处理文件名中的空格真的很糟糕,因为很多列表都是用空格分隔的——尤其是命令参数。例如,尝试通过 scp 复制带空格的文件!没有手动转义几乎是不可能的。
-
您应该完整阅读
http://mywiki.wooledge.org/BashPitfalls:-) 它会大大提高您的 bash 技能