LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 656|回复: 4

第一次写脚本,请大家帮着改改。

[复制链接]
发表于 2004-4-27 20:21:02 | 显示全部楼层 |阅读模式
[php]
#!/bin/bash
Usage ()
{
        echo "Usage: `basename $0` dir"
}

if [ "$1" = "-h" -o "$1" = "--help" ];then
        Usage
        exit 0
fi
if [ $# -le 0 ];then
        Usage
        exit 1
fi


for file in `find $1 -maxdepth 1`;
do
if [ -d $file ]  
then
        echo "cancled"
else
        iconv -f gb2312 -t utf-8 $file -o $file.ext
        mv -f $file.ext $file
fi
done
[/php]

这个脚本的作用是把指定目录下的文件编码从gb2312转化为utf-8。
现在有个问题是我能通过什么命令知道一个文件的编码吗,要不然这个脚本遇到非gb码的文件就会出错。
发表于 2004-4-27 20:53:40 | 显示全部楼层
file可以么?
 楼主| 发表于 2004-4-27 21:03:31 | 显示全部楼层
file 只能返回文件类型啊,不能返回文件编码:(
发表于 2004-4-27 21:42:52 | 显示全部楼层
file可以,但有时不准。
发表于 2004-4-27 22:31:44 | 显示全部楼层
既然用到了iconv,最好就用C吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表