开发者

One more bash (now .bat) script

开发者 https://www.devze.com 2023-01-07 04:58 出处:网络
I need to convert about 12000 TIF files in many directories, and try to write bash-script: #!/bin/bash

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 th开发者_StackOverflow中文版e .tif files.

%x - filename with .png extension

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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号