Re: [SLUG] Bash script

From: Bob Stia (rnr@sanctum.com)
Date: Tue May 24 2005 - 00:17:20 EDT


On Friday 20 May 2005 00:12, Kwan Lowe wrote:
> 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:/>
>
> ---------------------------------------------------------------------
Kwan & Eben,

Been busy with other things for the last few days but now I need to get
back to this. I have a gazillion jpg's to convert of all differeent
sizes.

You guys are assuming too much of me. Am an ultra-newbie at writing
scripts. Could you be slightly more specific?

Eben, You asked me about the first argument. Don't know what you mean
when you say, :>   echo $1

>What is $1 (yeah the first argument, but what in this case)?  DYM $i?"

and where would I put this,
>I would bracket the "convert" line with a "set -x"/"set +x" pair to see
>what's being executed.

Kwan,
You state it runs OK. Doesn't for me. I get thos line 35 thru line 41
"command not found" messages. Then you suggest, as per the following:
#########################################################################
>>echo Running $0
>> echo
>>
>> COUNT=0
>   Unused var?
Don't know what you mean by that.

>>
>> 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:
Don't know what you mean by that neither. I don't see anything in the
script with $VARNAME

>    BASENAME = `echo ${i} | sed -e 's/.jpg$//'`
Is this a replacement line for what is there? or is it added in the
script?

>Then:

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

>(Above line should not wrap)

>>        echo
>>   fi
>>
>> done;
>>
>> exit;
>>
----------------------------------------------------------------------
Thanks guys -Remember -newbie script writer

Bob S.

-----------------------------------------------------------------------
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:06:57 EDT