您现在的位置是: IT外包 ->实时操作系统 ->
 
本文关键字: 地址本的脚本
Google
 
地址本的脚本
作者: 不详 | 发布时间: 2008-06-11 12:40 | 信息类别: 实时操作系统 | 访问人次:
评论 推荐 打印 编辑 】 【 关闭
  

  
一个地址本的脚本,可供学shell的人参考


-------------addr.sh------------



#!/bin/bash
clear
. /etc/rc.d/init.d/functions

arg_count=$#
if [ $arg_count -eq 0 ]; then
FILENAME=/tmp/addr
elif [ $arg_count -eq 1 ]; then
FILENAME=$1
else
echo -e $"\007Usage:\n\t$0 filename"
exit 1
fi

add(){
echo
echo -e "\t\tN A M E :\c"
read name
echo
echo -e "\t\tP O S I T I O N :\c"
read position
echo
echo -e "\t\tT E L E P H O N E :\c"
read telephone
echo
echo -e "\t\tE _ M A L E :\c"
read email
echo -e "$name\t\t$position\t\t$telephone\t\t$email" >;>; $FILENAME
echo
echo -e "\t\tDo you wish to proceed?[y/n]:\c"
read proceed
echo
case $proceed in
y|Y|yes|Yes|YES)
add
;;
n|N|No|NO)
clear
main
;;
*)
echo -e "\t\tPlease input y|Y|yes|Yes|YES or n|N|No|NO"
exit 1
esac
}
proceed(){
case $1 in
y|Y|yes|Yes|YES)
$2 $3 $4 $FILENAME >; $FILENAME.tmp
mv $FILENAME.tmp $FILENAME
echo
echo -e "\t\tLine Deleted!"
;;
n|N|No|NO)
echo
;;
*)
echo -e "\t\tPlease input y|Y|yes|Yes|YES or n|N|No|NO"
echo
esac

}
del(){
clear
echo
echo -e "\t------------------------------------"
echo -e "\t|\t1. Del record by Line\t |"
echo -e "\t|\t2. Del record by Name\t |"
echo -e "\t|\t3. Del record by Tel \t |"
echo -e "\t|\t4. Show all record \t |"
echo -e "\t|\t5. Exit \t |"
echo -e "\t------------------------------------"
echo
echo -e "\t\t Your selection:\c"
read selection
echo
case $selection in
1)
echo -e "\t\tInput Start_Line_Number:\c"
read line1
echo
echo -e "\t\tInput End_Line_Number:\c"
read line2
echo
echo -e "\t\tLine$line1 to Line$line2 are:"
echo
echo -e "\t姓 名\t\t职 位\t\t 电 话\t\t\t电子邮件"
echo
sed -n ''$line1','$line2'p' $FILENAME |cat -n
echo
echo -e "\t\tDelete really?[y/n]:\c"
read proceed
proceed $proceed sed ''$line1','$line2'd'
;;
2)
echo -e "\t\tInput Name:\c"
read name
echo
echo -e "\t\trecord include $name are:"
echo
echo -e "\t姓 名\t\t职 位\t\t 电 话\t\t\t电子邮件"
echo
grep -w ^$name $FILENAME |cat -n
echo
echo -e "\t\tDelete really?[y/n]:\c"
read proceed
proceed $proceed grep -vw ^$name
;;
3)
echo -e "\t\tInput Telephone:\c"
read telephone
echo
echo -e "\t\trecord include $telephone are:"
echo
echo -e "\t姓 名\t\t职 位\t\t 电 话\t\t\t电子邮件"
echo
grep -w $telephone $FILENAME |cat -n
echo
echo -e "\t\tDelete really?[y/n]:\c"
read proceed
proceed $proceed grep -vw $telephone
;;
4)
echo
show
;;
5)
echo
main
;;
*)
clear
del
esac

echo
echo -e "\t\tDo you wish to proceed?[y/n]:\c"
read proceed
echo
case $proceed in
y|Y|yes|Yes|YES)
clear
del
;;
n|N|No|NO)
echo
main
;;
*)
echo -e "\t\tPlease input y|Y|yes|Yes|YES or n|N|No|NO"
echo
exit 1
esac
}


show(){
echo
echo -e "\t姓 名\t\t职 位\t\t 电 话\t\t\t电子邮件"
echo
cat -n $FILENAME
echo
echo -e "\t\tDo you wish to proceed?[y/n]:\c"
read proceed
echo
case $proceed in
y|Y|yes|Yes|YES)
main
;;
n|N|No|NO)
echo
exit 1
;;
*)
echo -e "\t\tPlease input y|Y|yes|Yes|YES or n|N|No|NO"
echo
exit 1
esac
}

main(){
clear
echo
echo -e "\t--------------------------------"
echo -e "\t|\t1. Add record \t |"
echo -e "\t|\t2. Del record \t |"
echo -e "\t|\t3. Show record\t |"
echo -e "\t|\t4. Exit \t |"
echo -e "\t--------------------------------"
echo
echo -e "\t\t Your selection:\c"
read selection
echo

case $selection in
1)
add
;;
2)
del
;;
3)
show
;;
4)
exit 1
;;
*)
main
esac
}
main
评论 推荐 打印 编辑 】 【 关闭
『相关链接』
序号
标题 发布日期
1
2008-05-20 16:51:11
2
2008-01-14 09:38:50
【郑重声明】【上海IT外包服务网】 刊载此文不代表同意其说法或描述,仅为提供更多信息,也不构成任何投资或其他建议。转载需经作者本人同意并注明出处。本网站有部分文章是由网友自由上传。对于此类文章本站仅提供交流平台,不为其版权负责。如果您发现本网站上有侵犯您的知识产权的文章,请发信至 或直接电话联系: 021-58879030
请您留言
『发表评论』
匿名发表 会员ID: 密码:

上海蝶应信息科技有限公司
上海市商城路341号紫光大厦1305室 +0086-21-58878998 11394019
dieying@541help.com +0086-21-58879030HappyFreeAngel@hotmail.com
Copyright@2007 IT-WAIBAO.COM Inc.沪ICP备05039378号 版权所有2007-2010 管理员登陆