Re: [SLUG] Bash script

From: Kwan Lowe (kwan@digitalhermit.com)
Date: Fri May 20 2005 - 00:12:40 EDT


Bob Stia wrote:
> Hello Sluggers,
>
> What is wrong with this script??

Script seems to work for me... You can try adding the following to debug:

   set -x

> --------------------------------------------------
> #!/bin/sh
>
> #########################################################################
> # A simple script to create smaller and lower quality images from
> # one directory to another
> #########################################################################
>
> # The file format you wish to change
> FROM=jpg
>
> # The end result file format
> TO=jpg
>
> # Options for "convert"
> CONVERT_OPTIONS='-quality 70 -geometry 800x600'
>
> # Pull the directory name for the title
> FROM_DIR=/home/bob/WebPages/PorschePilots/fog/temp
> TO_DIR=/home/bob/Webpages/PorschePilots/fog/carlouelimages

>
> #########################################################################
> # The actual conversion stuff
> # You can edit stuff below here to change how this works, or just stick
> # with the variables above (which should be good for most people
> #########################################################################
>
> echo Running $0
> echo
>
> COUNT=0
   Unused var?

>
> cd $FROM_DIR
> for i in *.$FROM; do
>
> echo $1
> if [ ! -e "$TO_DIR/$i" ] # Process only files not already done
> then
> echo Converting $i... with $CONVERT_OPTIONS
> convert $CONVERT_OPTIONS $FROM_DIR/$i $TO_DIR/${i%%$FROM}$TO

   As a general practice I tend to use ${VARNAME} instead of just
$VARNAME. Won't matter here, but can help with debugging. Instead of
the above notation, you can also generate the filenames with:

    BASENAME = `echo ${i} | sed -e 's/.jpg$//'`

Then:

    convert ${CONVERT_OPTIONS} ${FROM_DIR}/${i} ${TO_DIR}/${BASENAME}.${TO}

(Above line should not wrap)

> echo
> fi
>
> done;
>
> exit;
> ----------------------------------------------------------------------
> This is what I get:
>
> /home/bob/commands/ImageMagickConvert: line 35: : command not found
> /home/bob/commands/ImageMagickConvert: line 36: : command not found
> /home/bob/commands/ImageMagickConvert: line 37: : command not found
> /home/bob/commands/ImageMagickConvert: line 38: : command not found
> /home/bob/commands/ImageMagickConvert: line 39: : command not found
> /home/bob/commands/ImageMagickConvert: line 40: : command not found
> /home/bob/commands/ImageMagickConvert: line 41: : command not found
> bob@EasyStreet:/>

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:02:12 EDT