我正在嘗試編寫腳本,它將裁剪大尺寸照片並將其調整爲高清壁紙。BASH中帶空格的文件名
#! /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
但似乎腳本有具有文件名的空格(翻滾Weed.jpg)的問題。我怎樣才能解決這個問題?
答案已經在下面給出,但我只想補充說,shell腳本對於處理文件名中的空格非常不利,因爲太多的列表是空格分隔的 - 特別是命令參數。例如,嘗試通過scp複製帶有空間的文件!沒有手動轉義幾乎是不可能的。 – Timmmm 2010-10-19 11:30:10
您應該完整閱讀'http:// mywiki.wooledge.org/BashPitfalls' :-)它將大大提高您的bash技能 – Benoit 2010-10-19 16:08:01