views:

93

answers:

1

I need to convert about 12000 TIF files in many directories, and try to write bash-script:

#!/bin/bash
find -name "*.tif" | while read f
do
 convert "$f" "${f%.*}.png"
 rm -f "$f"
done

Why it say: x.sh: 6: Syntax error: end of file unexpected (expecting "do") and what I should to do?


Great thanks to you all, men, but I was cheated: the computer on which this should be run out works under Windows. I don't know how to work with strings and cycles in DOS, now my script look like:

FOR /R %i IN (*.tif) DO @ (set x=%i:tif%png) & (gm convert %i %xtif) & (erase /q /f %i)

%i - one of the .tif files.

%x - filename with .png extension

gm convert - graphics magick utility, work similarly with image magick's convert on linux.

+3  A: 

The syntax looks okay, but if it's a problem with EOLs, try adding a semicolon before the do to fix the syntax error (or check the newlines are actually present/encoded as ghostdog74 suggests):

find -name "*.tif" | while read f ; do # ...

Note that the find/read pattern isn't robust. Use can use find's exec capability directly (thanks Philipp for the inline command):

find -name "*.tif" -exec sh -c 'file=$0 && convert "$file" "${file%.tif}.png"' '{}' ';' -delete
p00ya
Philipp
@Philipp: nice inline invocation ;) @pilcrow: I agree, you need either a newline *or* a semicolon (not both), but it's worth trying with, since a missing newline (e.g. forgotten when typed inline, or due to an encoding issue) seems the mostly likely cause of that syntax error to me.
p00ya