A case of a batch conversion directory of File encoded shell script code.
Requirements Description:
As a result of turning Linux from Windows, many original win under the GBK file needs to be converted into UTF8.
The following script only judges that a UTF8 file is converted to a UTF8 file, and that the default UTF8 file is GBK, and if the file type is inconsistent, it needs to be modified.
Example:
Copy Code code as follows:
#!/bin/bash
# File Name:iconv.sh
# Author:wanggy
# site:www.jb51.net
#
Show_file ()
{
For file in ' ls $ '
Todo
If [-D $/$file];then
#目录递归调用show_file函数
Show_file "/" $file
Else
#文件
echo $ "/" $file
File_type= ' file $ '/' $file '
Type= ' echo $file _type |grep UTF-8 '
If [-Z "$type"];then
echo "is null-UTF-8 encoded, converted"
Iconv-f gbk-t UTF8 $ "/" $file-o $/"$file
Else
echo "UTF8 encoding without conversion"
Fi
Fi
Done
}
Path=./shell
Show_file $path