【发布时间】:2012-01-11 18:20:39
【问题描述】:
我知道这很脏,绝对不是最好的方法。我拼凑了一堆不同的脚本来尝试完成这项工作,但我不断收到“convert.sh:24:Bad Substitution”错误。也许有人可以帮我清理它并让它工作。谢谢。
#!/bin/bash
rm -v -R temp/
mkdir temp
mkdir temp/raw
DIR="/media/mdrive/dump/"
if [ -z "$DIR" ]; then
echo >&2 "Syntax: $0 <directory>"
exit 1
fi
if [ ! -d "$DIR" ]; then
echo >&2 "\"$DIR\" is not a directory"
exit 1
fi
cd "$DIR"
for file in *.jpg *.JPG; do
first=${file::1}
mkdir -p $first && mv $file $first/;
done
cp -v -R /media/mdrive/dump/* /media/mdrive/stagingForUpload/
cp -v -f -R /media/mdrive/dump/* /media/mdrive/original/
cp -v -R /media/mdrive/dump/* temp/raw/
rm -v -R /media/mdrive/dump/*
# Creates directories
mkdir temp/images
mkdir temp/medium
mkdir temp/large
# Copies ~/Desktop/raw into ~/Desktop/small, medium & large
cp -v -R temp/raw/* temp/images/
cp -v -R temp/raw/* temp/medium/
mv -v temp/raw/* temp/large/
rm -v -R temp/raw/
# Converts images into respective size and quality
find temp/images/* -maxdepth 2 -iname "*.jpg" -print0 | xargs -0 mogrify -resize 100x100">" -quality 80 -compress JPEG -monitor -strip
find temp/medium/* -maxdepth 2 -iname "*.jpg" -print0 | xargs -0 mogrify -resize 428x270"^" -quality 80 -compress JPEG -monitor -strip
find temp/medium/* -maxdepth 2 -iname "*.jpg" -print0 | xargs -0 mogrify -resize 428x270">" -quality 80 -compress JPEG -monitor -strip
find temp/large/* -maxdepth 2 -iname "*.jpg" -print0 | xargs -0 mogrify -resize 800x800">" -quality 85 -compress JPEG -monitor -strip -gravity SouthEast -draw 'text 10,10 "www.kmstools.com"'
#Batch Renames
find temp/medium -iname "*.jpg" -printf 'mv %p %p\n' | sed 's/\.jpg$/_MED\.jpg/' | while read l; do eval $l; done
find temp/large -iname "*.jpg" -printf 'mv %p %p\n' | sed 's/\.jpg$/_LRG\.jpg/' | while read l; do eval $l; done
# Consolidates images into image directory
mv temp/large temp/images
mv temp/medium temp/images
# Removes Thumbs.db
find temp/images/ -type f -iname Thumbs.db | while read FILE ; do rm "${FILE}" ; done
# Copies images/ to website_directory_structure
cp -v -R temp/images/* /media/mdrive/website_directory_structure/
# Uploades files to Old KMS Webserver
ncftpput -m -R -F -u <username> -p <password> <webserver>.com /public_html/images/ temp/images/
【问题讨论】:
-
您是否使用
-x运行它以查看究竟是哪一行给了您错误? -
第 24 行似乎是问题
-
嗯,这显然不是一个糟糕的替代。使用
-x运行它会让您更准确地了解它是如何计算行数的。 -
试图将代码粘贴到此评论中至少可以说令人沮丧
-
line 1 + set -e line 2 + rm -v -R temp/ line 3 移除目录:
temp/raw' **line 4** removed directory:temp' line 5 + mkdir temp line 6 + mkdir temp/raw line 7 + DIR=/media/mdrive/dump 第 8 行 + [ -z /media/mdrive/dump ] 第 9 行 + [ ! -d /media/mdrive/dump ] line 10 + cd /media/mdrive/dump line 11 convert.sh: 25: 错误替换
标签: bash imagemagick mogrify