基于前面两篇文章的介绍,本文笔者自己编写了一个用于优化源代码编译的脚本,主要功能是两个:
1.转换dos文件格式为unix文件,去除行尾的^M
2.去除多余行尾空格
shell脚本如下,欢迎品鉴:
#!/bin/sh
if [ x$1 = x ]; then
echo "Please pass an arg as source code path!!!\n"
exit 1
fi
SRC=$(find $1 -name "*.c" -o -name "*.h")
echo "Handle Source Files:"
echo "${SRC}"
for file in ${SRC}
do
sed -i -e 's/\r$//' $file
sed -i -e 's/\s*$//' $file
done