我从一位离开公司的同事那里继承了一个剧本,在编写脚本和保留笔记方面,我们可以说是懒惰的。在他离开之前,他坚持认为这个剧本工作得很好,但是永远不会花时间向我展示或验证它在新环境中是否有效,现在我坚持使用它。
它似乎工作正常,除了它没有按照预期写出CSV这一事实。它应该给我图像的文件名,宽度,高度和总像素数。我得到的是文件名,空白,空白,variablenamevariablename。任何帮助将不胜感激:
#!/bin/bash
#
# This script will display
# all images included
ORIGDIR=~/Desktop/EPUB_Fix/Needs_Work
DIRECTORY=~/Desktop/EPUB_Fix/Work_Area
DESTINATION=~/Desktop/EPUB_Fix/Fixed
PROCESSED=~/Desktop/EPUB_Fix/Original_Files
EPUB=*.epub
cd ~/Desktop
cp -v $ORIGDIR/$EPUB $DIRECTORY
mv -v $ORIGDIR/$EPUB $PROCESSED
#cd $PROCESSED
#rename 's@(.*?)\.epub@$1_orig.epub@' $EPUB
cd $DIRECTORY
for epubfile in $(ls "$DIRECTORY"/$EPUB); do
echo
echo =================================
echo
zipfile=$(basename $epubfile .epub).zip
directoryname=$(basename $zipfile .zip)
mv -v "$epubfile" "$DIRECTORY"/"$zipfile"
ziperror=0
ziperror=$(unzip -t "$DIRECTORY"/"$zipfile" > /dev/null)$?
if [ $ziperror -eq "0" ]; then
unzip -o "$DIRECTORY"/"$zipfile" -d "$DIRECTORY"/"$directoryname"
echo
echo "Printing file name to CSV"
for eisbn in $(find $DIRECTORY/$directoryname); do
EVALUE=0
while [ $EVALUE -eq 0 ]; do
eisbn=$(basename $directoryname)
echo "EISBN: $eisbn" > $eisbn.csv
let EVALUE=1
done
done
echo "Printing image names"
echo >> $eisbn.csv
echo Name,Width,Height,Total >> $eisbn.csv
echo >> $eisbn.csv
echo "Printing total images with their sizes"
echo
for image in $(find $DIRECTORY/$directoryname -name "*.jpg" -o -name "*.jpeg" -o -name "*.png" -o -name "*.gif"); do
size="$(identify --format "%w %h" "$image")"
width="${size%% *}"
height="${size##* }"
imagename=$(basename $image)
total=$(($width * $height))
echo $imagename,$width,$height,$total >> $eisbn.csv
done
for dbfile in $(find $DIRECTORY/$directoryname -name Thumbs.db); do
rm -v $dbfile
done
for dsfile in $(find $DIRECTORY/$directoryname -name .DS_Store); do
rm -v $dsfile
done
for plistfile in $(find $DIRECTORY/$directoryname -name iTunesMetadata.plist); do
rm -v $plistfile
done
for ologfile in $(find $DIRECTORY/$directoryname -name Output.log); do
rm -v $ologfile
done
for csvfile in $(find $DIRECTORY -name *.csv); do
mv -v $csvfile $LOG
done
cd "$DIRECTORY"/"$directoryname"
cp -v -f /media/sf_epubs/mimetype "$DIRECTORY"/"$directoryname"
zip -X -0 $DESTINATION/$directoryname.zip mimetype
zip -r $DESTINATION/$directoryname.zip * -x mimetype
mv -v $DESTINATION/$directoryname.zip $DESTINATION/$directoryname.epub
rm -v -r "$DIRECTORY"/"$directoryname"
rm -v "$DIRECTORY"/$zipfile
fi
done
答案 0 :(得分:0)
行size="$(identify --format "%w %h" "$image")"
格式选项应为-format
而不是--format
尝试将该行更改为并查看是否有帮助
size =" $(识别-format'%w%h' $ image)"