在每一首弦乐回荡
面前端着一份报纸。
那奔跑、歌唱、亲吻、花束,
告诉我,为什么你的心象一座纤小的丛林
的老病的奈何天,哈哈
直接处理文件没关系的吧。
#!/bin/shcontactBook=contact.lst
name=
phone=
email=
addr=
ret=
addContact()
{
if [ "$newname" = "" ]then
echo "姓名不能为空"
return 1
fi
chk=`grep -w $newname $contactBook`
if [ "$chk" != "" ]then
echo "姓名是 $newname 的联系人已存在"
return 1
fi
read -p "输入电话号码: " newphone
if [ "$newphone" = "" ]then
echo "电话不能为空\n"
return 1
fi
read -p "输入Email: " newmail
read -p "输入地址: " newaddr
newline=`echo $newname $newphone $newmail $newaddr`
echo "$newline" >> $contactBook
ret=0
return 0
}
findContact()
{
read -p "输入要查找的姓名: " nametofind
line=`grep -w ^$nametofind $contactBook`
if [ "$line" != "" ]then
name=`echo $line | awk '{print $1}'`
phone=`echo $line | awk '{print $2}'`
email=`echo $line | awk '{print $3}'`
addr=`echo $line | awk '{print $4}'`
printf "%-20s %-20s %-32s %-64s\n" "姓名" "电话" "邮箱" "地址"
printf "%-16s %-15s %-32s %-64s\n" $name $phone $email $addr
ret=0
else
echo "$nametofind 没找到"
ret=-1
return 1
fi
}
updContact()
{
findContact
if [ $ret -lt 0 ]then
return 1
fi
read -p "输入新电话号码: " newphone
if [ "$newphone" = "" ]then
newphone=$phone
fi
read -p "输入新Email: " newmail
if [ "$newmail" = "" ]then
newmail=$mail
fi
read -p "输入新地址: " newaddr
if [ "$newaddr" = "" ]then
newaddr=$addr
fi
newline=`echo $name $newphone $newmail $newaddr`
sed "/\<$name\>/c $newline" $contactBook > ${contactBook}.tmp
mv ${contactBook}.tmp $contactBook
}
menu()
{
cat <<EOF
1. 新增
2. 查找
3. 修改
q. 退出
EOF
}
menu
while [ 1 -eq 1 ]
do
ret=0
read -p "输入选项: " ch
case "$ch" in
"1")
addContact
"2")
findContact
"3")
updContact
"q"|"Q")
exit
*)
echo "选项错误"
esac
done
echo "exit"
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)