Shell脚本把文件从GBK转为UTF-8编码
网络编程
shell 脚本:
#!/bin/sh ## ## convert file from GB2312 to UTF-8 ## path="$1" unset opt if [ "$2" = "force" ]; then opt="-c -s" fi if [ -z "$path" ]; then echo "nUsage: $0 <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=`dirname $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
Shell脚本解压rpm软件包
有时候需要从RPM包中提取文件,而又没有安装且不想安装rpm相关的库和程序,此时下面这个小小的绿色脚本可以帮你达成愿望。注:1.此脚本来源于Intern
shell脚本中常见的一些特殊符号和作用详解
在编写Shell脚本时,我们需要会用到各种各样的特殊符号,通过这些特殊符号可以使我们编写的代码更加简洁和高效,这里给大家汇总下:1、{}大括号:
Linux Shell中的特殊符号和含义简明总结(包含了绝大部份)
在LinuxShell中有很多的特殊符号,这对于我们写Shell脚本时要特别留意:一方面要知道这些特殊符号的用法,这些符号用好了可以达到事半功倍的效果;
标签:脚本,特殊符号,中有,帮你,高效