1. 一,将SVN版本信息添加到我们的程序版本中

  2.  
  3. 1,使用sed命令修改源代码/Makefile中的版本号,添加SVN版本信息:

  4.  
  5. #!/bin/sh
  6. #File Name: build-l200.sh

  7.  
  8. #Get the SVN version number
  9. svn_ver=`svn up|grep revision|awk -F' ' '{ print $3 }'|awk -F'.' '{print $1}'`
  10. echo "SVN Version: $svn_ver"

  11.  
  12. #Find the Version line
  13. line=`sed -n '/#define DROPBEAR_VERSION/=' options.h`

  14.  
  15. #Instead the original version by mine
  16. sed -i -e ${line}s"/.*/#define DROPBEAR_VERSION \"0.51 Build ${svn_ver}\"/" options.h

  17.  
  18. #compile the source code
  19. make

  20.  
  21. 2, 将SVN版本信息放入version.h头文件中,在源代码中在包含该头文件并引用他们:
  22. a, makefile中定义版本信息并调用scripts/mkversion脚本:
  23. CROSS_COMPILE =
  24. ARCH= L200

  25.  
  26. MAJOR=1
  27. MINOR=0
  28. REVER=0
  29. SVNUP=1

  30.  
  31. all: entry version at
  32. version:
  33. @echo " ";
  34. @echo " =========================================";
  35. @echo " ** Create Software Version Head File **";
  36. @echo " =========================================";
  37. sh scripts/mkversion ${SVNUP} ${MAJOR} ${MINOR} ${REVER}

  38.  
  39. b, scripts/mkversion脚本:

  40.  
  41. #!/bin/sh

  42.  
  43. GET_SVN=$1
  44. MAJOR=$2
  45. MINOR=$3
  46. REVER=$4

  47.  
  48. if [ $GET_SVN -eq 0 ]
  49. then
  50. echo "============ Skip svn update ============"
  51. exit;
  52. else
  53. echo "============ SVN update and get svn version now ============"
  54. svn up
  55. svn_ver=`svn up|grep revision|awk -F' ' '{ print $3 }'|awk -F'.' '{print $1}'`

  56.  
  57. echo "/* This is generate by makefile , don't Edit it by hand */" > version.h
  58. echo "#define MAJOR ${MAJOR}" >>version.h
  59. echo "#define MINOR ${MINOR}" >>version.h
  60. echo "#define REVER ${REVER}" >>version.h

  61.  
  62. if [ ! -z $svn_ver ]
  63. then
  64. echo "#define SVNVER $svn_ver" >>version.h
  65. else
  66. echo "#define SVNVER 0000" >>version.h
  67. fi
  68. fi

  69.  
  70. 3, 使用sed修改Makefile文件: 替换行/行前插入/行后插入

  71.  
  72. 例一:
  73. FILE=src/pkcs11/Makefile

  74.  
  75. #将文件中所有的$KEY替换成$INSTEAD
  76. KEY="-module -shared -avoid-version -no-undefined"
  77. INSTEAD="-module -static -avoid-version -no-undefined"
  78. sed -i -e "s/${KEY}/$INSTEAD/g" $FILE

  79.  
  80. #找到某一行,并在其后插入一些行;
  81. FILE=src/libopensc/Makefile
  82. line=`sed -n '/all: all-am/=' $FILE`
  83. #替换该行内容
  84. sed -i -e ${line}s"/.*/all: all-am L200_rebuildLib/" $FILE
  85. #在该行后插入一些新的行
  86. sed -i -e `expr $line + 1`a"L200_rebuildLib:" $FILE
  87. sed -i -e `expr $line + 2`a"\\\tcp \`dirname \${abs_top_srcdir}\`/pcsc-lite-1.5.5/src/.libs/libpcscl
  88. ite.a \${abs_srcdir}/.libs" $FILE
  89. sed -i -e `expr $line + 3`a"\\\tsh \${abs_srcdir}/L200_rebuildLib.sh \${abs_srcdir}\n" $FILE

  90.  
  91. 找到某一行,在该行前插入一行:
  92. FILE=src/Makefile
  93. #找到要修改的行号
  94. line=`sed -n '/CFLAGS = -Wall -fno-common/=' $FILE`
  95. #替换该行的内容
  96. sed -i -e ${line}s"/.*/CFLAGS = -Wall -fno-common -O2 -Wl,-elf2flt='-s 262144'/" $FILE
  97. #在该行前插入一行注释
  98. sed -i -e ${line}i"# Set stack size as 256K" $FILE

  99.  
  100. 找到某一行,删除该行第一个字符:
  101. KEY="#am__EXEEXT_1 = cryptoflex-tool"
  102. line=`sed -n "/$KEY/=" $FILE`

  103.  
  104. if [ $line ] ; then #如果变量不为空,即找到该行
  105. sed -i -e "${line}s/.//1" $FILE #这里的1即为第一个字符,若修改第二个字符则改为2
  106. sed -i -e "`expr $line + 1`s/.//1" $FILE
  107. sed -i -e "`expr $line + 2`s/.//1" $FILE
  108. fi

  109.  
  110. 例二:
  111. CROSS=/opt/buildroot_350/build_arm/staging_dir/bin/arm-linux-uclibc-
  112. # | -----------------------------
  113. # | Cross compile iproute2-2.6.34
  114. # | -----------------------------

  115.  
  116. if [ ! -d iproute2-2.6.34 ] ; then
  117. tar -xjf iproute2-2.6.34.tar.bz2
  118. fi

  119.  
  120. if [ -d iproute2-2.6.34 ]; then
  121. cd iproute2-2.6.34
  122. FILE=Makefile
  123. sed -i -e 38s"/.*/SUBDIRS=lib tc/" $FILE

  124.  
  125. line=`sed -n '/^CC = gcc$/=' $FILE`
  126. if [ $line ]; then
  127. sed -i -e ${line}s"@.*@CROSS=$CROSS@" $FILE //由于$CROSS中中包含sed默认分隔符"\",所以我们这里改用@作为分隔符
  128. sed -i -e `expr $line + 0`a"CC = \${CROSS}gcc" $FILE
  129. sed -i -e `expr $line + 1`a"AR=\${CROSS}ar" $FILE
  130. sed -i -e `expr $line + 2`a"AS=\${CROSS}as" $FILE
  131. sed -i -e `expr $line + 3`a"LD=\${CROSS}ld" $FILE
  132. sed -i -e `expr $line + 4`a"RANLIB=\${CROSS}ranlib" $FILE
  133. fi

  134.  
  135. make && cd -
  136. fi

  137.  
  138. # | -----------------------------
  139. # | Cross compile redir-2.2.1
  140. # | -----------------------------

  141.  
  142. if [ ! -d redir-2.2.1 ] ; then
  143. tar -xzf redir-2.2.1.tar.gz
  144. fi

  145.  
  146. if [ -d redir-2.2.1 ]; then
  147. cd redir-2.2.1
  148. FILE=Makefile
  149. sed -i -e s":^CC = gcc$:CC = ${CROSS}gcc:" $FILE //这里选用":"作为sed 分隔符
  150. make && cd -
  151. fi

  152.  

  153.  
  154. 二,一些常用的alias:

  155.  
  156. alias vt100='export TERM=vt100'
  157. alias linux='export TERM=linux'
  158. alias maek='make'
  159. alias rmsvn='find -name .svn -exec rm -rf {} \;'
  160. alias rmgdb='find -iname "*.gdb" -exec rm -rf {} \;'
  161. alias rmdep='find -name .depend -exec rm -rf {} \;'
  162. alias myindent='indent -npro -kr -bl -nce -bli0 -i2 -ts2 -sob -l80 -nfc1 -ss -ncs'
  163. alias myctages='ctags --c-kinds=+defglmnstuvx --langmap=c:.c.h.ho.hem.het.hec.hev.him.hit.hic.hiv -R .'

  164.  
  165. alias nocvim='mv ~/.vimrc ~/.vimrcb'
  166. alias cvim='mv ~/.vimrcb ~/.vimrc'
  167. alias mntwinxp='sudo mount -t cifs -o username="username",password="password" //Winxp_ipaddr/linux /home/username/winxp/'

  168.  

  169.  

  170.  
  171. 用于在文件中查找的脚本:
  172. #!/bin/sh
  173. # Description: This shell script used to grep the "key" in all the files
  174. find -iname "*$suffix" | xargs grep "$key"
  175. find -iname "*$suffix" | xargs grep "\<$key\>"
  176. # in current folder.
  177. # Author: guowenxue(guowenxue@gmail.com)
  178. # Version: 1.0.0 (Release by guowenxue on 04th Feb. 2010)
  179. # ChangeLog: None
  180. #

  181.  
  182. if [ $# -lt 1 ] ; then
  183. echo " Usage: $0 key [-g] [suffix]"
  184. echo "Example1: mygrep haha"
  185. echo "Example2: mygrep haha -g"
  186. echo "Example1: mygrep haha *.c"
  187. echo "Example1: mygrep haha -g *.c"
  188. exit;
  189. fi

  190.  
  191. key=$1 #The grep key

  192.  
  193. if [ $# = 1 ] ; then
  194. grep -n "$key" -r *
  195. elif [ $# = 2 ] ; then
  196. if [ $2 = "-g" ] ; then
  197. grep -n "\<$key\>" -r *
  198. else
  199. suffix=$2
  200. find -iname "$suffix" | xargs grep -n "$key"
  201. fi
  202. else # Arguments more than 3
  203. if [ $2 = "-g" ] ; then
  204. suffix=$3

  205.  
  206. elif [ $3 = "-g" ]; then
  207. suffix=$2
  208. fi

  209.  
  210. find -iname "$suffix" | xargs grep -n "\<$key\>"
  211. fi

  212.  

  213.  
  214. [guowenxue@localhost drivers]$ mygrep 15000400
  215. csps/lpc313x/include/lpc313x_chip.h:#define LCD_INTERFACE_BASE 0x15000400
  216. [guowenxue@localhost drivers]$ mygrep 15000400 .h
  217. ./csps/lpc313x/include/lpc313x_chip.h:#define LCD_INTERFACE_BASE 0x15000400
  218. [guowenxue@localhost drivers]$ mygrep 15000400 .h -g
  219. [guowenxue@localhost drivers]$ mygrep 15000400 -g .h

  220.  
  221. Sed命令去掉补丁文件中首字符"+",获取C代码文件:
  222. [guowenxue@localhost spi]$ sed -i 's/^+//' tsc2046.h

  223.  

  224.  
  225. 清除所有ARP缓存表:
  226. for ip in `seq 1 6`; do arp -d 192.168.5.$ip; done