[Nottingham] Bash script problem
Ron Wilton
ron_w_add at yahoo.co.uk
Sun Mar 1 10:18:20 UTC 2009
Hello everyone
I've written the following bash script.
#
for file in *.jpg ; do
# creating the thumbnail filename
thumbfile="$(basename "$file" .jpg)th.jpg"
# reading the width and height of the jpg
let WIDTH=exiftags $file | grep "Image Width"
let HEIGHT=exiftags $file | grep "Image Height"
if [ WIDTH > HEIGHT ] ; then
# convert as landscape
convert -thumbnail 200x150 "$file" thumbnails/"$thumbfile"
else
# convert as portrait
convert -thumbnail 150x200 "$file" thumbnails/"$thumbfile"
fi
done
#
and even though it does what I want (ie create thumbnails of jpg files in the correct landscape/portrait orientation) I get the following errors:-
profam: line 20: let: 20080720-142448.jpg: syntax error: invalid arithmetic operator (error token is ".jpg")
profam: line 21: let: 20080720-142448.jpg: syntax error: invalid arithmetic operator (error token is ".jpg")
(where line 20 is the 'let WIDTH=exiftags...' line, and 'profam' is the name of my bash script).
I've tried the following changes, which also produces errors.
1) removed the let
WIDTH=exiftags $file | grep "Image Width"
HEIGHT=exiftags $file | grep "Image Height"
errors:-
profam: line 20: 20080720-142448.jpg: command not found
profam: line 21: 20080720-142448.jpg: command not found
2) added '$'
WIDTH=exiftags $file | grep "Image Width"
HEIGHT=exiftags $file | grep "Image Height"
if [ $WIDTH > $HEIGHT ] ; then
errors:-
profam: line 20: 20080720-142546.jpg: command not found
profam: line 21: 20080720-142546.jpg: command not found
profam: line 23: 1: ambiguous redirect
3) put the 'let' back in
let WIDTH=exiftags $file | grep "Image Width"
let HEIGHT=exiftags $file | grep "Image Height"
if [ $WIDTH > $HEIGHT ] ; then
errors:-
profam: line 20: let: 20080720-142546.jpg: syntax error: invalid arithmetic operator (error token is ".jpg")
profam: line 21: let: 20080720-142546.jpg: syntax error: invalid arithmetic operator (error token is ".jpg")
profam: line 23: 1: ambiguous redirect
Can anyone see what I'm doing wrong?
Thanks for any help
Ron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.lug.org.uk/pipermail/nottingham/attachments/20090301/84b88777/attachment.htm
More information about the Nottingham
mailing list