shell字符串处理完整脚本(三)
#!/bin/bash
#
string="Hello LiLei,LiLei is my friend,Hello GoodBey"
function print_tips
{
echo "------------------------"
echo "(1) ´打印string长度"
echo "2.删除字符串中所有的LiLei"
echo "3.替换第一个Hello 为你好"
echo "4.替换全部的Hello 为你好"
echo "------------------------"
}
function len_of_string
{
echo "${#string}"
}
function del_LiLei
{
echo "${string//LiLei/}"
}
function rep_Hello_nihao_first
{
echo "${string/Hello/nihao}"
}
function rep_all
{
echo "${string//Hello/nihao}"
}
while true
do
echo "$string"
echo
print_tips
read -p "Pls input your choice(1|2|3|4|q|Q) : " choice
case $choice in
1)
len_of_string
;;
2)
del_LiLei
;;
3)
rep_Hello_nihao_first
;;
4)
rep_all
;;
q|Q)
exit
;;
*)
echo "Error,input only in {1|2|3|4|q|Q}"
;;
esac
done