意外标记'done'附近的cygwin语法错误 [英] cygwin syntax error near unexpected token `done'

查看:66
本文介绍了意外标记'done'附近的cygwin语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用cygwing脚本将ansi文件的编码转换为utf8编码.下面是脚本:

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

但是我在意外的标记'done'附近收到语法错误."webazmoon7"是我尝试在其中转换编码文件的目录.有什么问题吗?

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?

推荐答案

尝试引用变量并更改您的 find/while 循环,如下所示:

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 "*")

这篇关于意外标记'done'附近的cygwin语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆