Search code examples
bashcygwin

cygwin syntax error near unexpected token `done'


I am trying to convert encoding of my ansi files to utf8 encoding using cygwing script. Below is the script:

#!/bin/bash
FROM=ANSI
TO=UTF-8
ICONV="iconv -f $FROM -t $TO"
# Convert
find webazmoon7/ -type f -name "*" | while read fn; do
cp ${fn} ${fn}.bak
$ICONV < ${fn}.bak > ${fn}
rm ${fn}.bak
done

but i get syntax error near unexpected token `done'. "webazmoon7" is the directory that i am trying to convert files encoding in it. What is the problem?


Solution

  • Try quoting the variables and changing your find/while loop like this:

    while read -r fn; do
       cp "${fn}" "${fn}.bak"
       iconv -f "$FROM" -t "$TO" < "${fn}.bak" > "${fn}"
       rm "${fn}.bak"
    done < <(find webazmoon7/ -type f -name "*")