Shell script:
#!/bin/sh # # # Convert file from GB2312 to UTF-8 # path= "$" unset opt if ["$" = "Force"]; Then opt= "-c-s" fi if [-Z "$path"]; Then echo "Nusage: $ <file or dir>n" elif [!-e "$path"]; Then echo "Nerror:destination: $path does not exist.n" fi if [F "$path"]; Then echo "Converting $path (GBK--> utf-8) ... "If File" $path "|grep-q UTF-8 >/dev/null; Then echo "already converted" Else iconv-f GBK $opt-T Utf-8 "$path" >/tmp/$$.tmp if [$?-eq 0]; Then echo "Success" Mv-f/tmp/$$.tmp "$path" Else echo "Failed" fi fi elif [-D "$path"]; Then Path= ' echo ' $path/' |sed ' s//////' find ' $path '-path ' $path. * "-prune-o-type-f-print|while read I do dir= ' di Rname $i ' file= ' basename $i ' echo ' converting $dir/$file (GBK--> utf-8) ... "Iconv-f gbk-t utf-8 $opt" $i " ; /tmp/$$.tmp 2>/dev/null if [$-eq 0]; Then echo "Success" Mv-f/tmp/$$.tmp "$i" Else echo "Failed" fi done fi