开始需要最简单的例子
1.简单遍历一个目录 做删除操作
$2 为输入参数
filelist=`ls /log/backup`
for filename in $filelistdo
if [ $2 != $filename ]; then
rm -rf /log/backup/$filename
fi
done
2. if/eles
#! /bin/sh
if [ -f /bin/bash ]
then echo "/bin/bash is a file"
else echo "/bin/bash is NOT a file"
fi
if :;then echo "always true"; fi
~
3 case 语句
注意:不用break; 每种情况结束用;; esac 结束标志
#! /bin/sh
echo "Is it morning? Please answer yes or no."
read YES_OR_NO
case "$YES_OR_NO" in
yes|y|Yes|YES)
echo "Good Morning!";;
[nN]*)
echo "Good Afternoon!";;
*)
echo "Sorry, $YES_OR_NO not recognized. Enter yes or no."
exit 1;;
esac
exit 0
转载自:http://learn.akae.cn/media/ch31s05.html
如何使用Vi显示出文本行末尾的^M符号
vi -d file
去掉所有多余的^M:
:%s/^M$//g
:%s/^M$//g
格式化字符串
而在linux中echo -e "aa\c">>a.txt
echo "bb">>a.txt
cat a.txt
显示 aabb