user388871
user388871

Reputation: 21

One more bash (now .bat) script

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.

Upvotes: 2

Views: 205

Answers (1)

p00ya
p00ya

Reputation: 3709

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

Upvotes: 3

Related Questions