[Nottingham] Bash script problem

Graeme Fowler graeme at graemef.net
Sun Mar 1 15:05:41 UTC 2009


Hi Ron

On Sun, 2009-03-01 at 10:18 +0000, Ron Wilton wrote:
> 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")

Firstly, "let" is only used arithmetic assignment - anything with text
in isn't a valid result.
Secondly, to assign the output from a command to a variable you need to
use backticks. In my case, using exiftool, I'd do this:

SIZE=`exiftool $file | grep "Image Size" | \
    sed 's/^.\+: //'`
WIDTH=`echo $SIZE | sed 's/x.\+//'`
HEIGHT=`echo $SIZE | sed 's/^.\+x//'`

In Perl terminology, TMTOWTDI :)

Graeme




More information about the Nottingham mailing list