[ale] Embarassing script question

Geoffrey esoteric at 3times25.net
Wed Aug 6 09:28:44 EDT 2003




Matthew Brown wrote:
> Here's a bash scripting question I should problem already know the
> answer to:
> 
> I wrote a tiny script yesterday to convert a slew of photos from BMP to
> JPG.  The qquickest route i found was through the PPM format, so the
> current script looks like:
> 
> #!/bin/sh
> bmptoppm $1 | ppmtojpeg > $1.jpg
> 
> Now the annoyances are as follows:
> 1.    The filename ends up something like Pic001.bmp.jpg.
> 2.    I can't find a way to handle odd filenames, like "PC Beach001.bmp"
> and "LasVegas&JumpRope001.bmp".

I see two issues here.  You likely want to be rid of the bmp in the file 
  name and you're probably having problems with the funky characters in 
some of the names (&, space..).  Try this:

for fn in *;do
	bmptoppm "$fn" | ppmtojpeg > "${fn%.bmp}.jpg"
done

The ${fn%.bmp}.jpg will replace the trailing '.bmp' with '.jpg'

The double quotes around the to will stop the shell from interpreting 
the special characters (space, &)

Another possibility which is a bit easier would be to use 'convert' 
which is part of the ImageMagick package.  replace your 'bmptoppm.....' 
line with the following:

convert "$fn" "${fn%.bmp}.jpg"

Have fun...


> 
> Any takers?
> 
> BTW, I don't have any idea how they got such odd names.
> 

-- 
Until later: Geoffrey		esoteric at 3times25.net

The latest, most widespread virus?  Microsoft end user agreement.
Think about it...

_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale





More information about the Ale mailing list