您的位置:首页 > 文档 > Shell >
 文章分类 

地址本的脚本


创建:2005-10-26 00:49:46
作者:Unlinux
来自: http://www.Unlinux.com

一个地址本的脚本,可供学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 $"07Usage:nt$0 filename"
exit 1
fi

add(){
echo
echo -e "ttN A M E :c"
read name
echo
echo -e "ttP O S I T I O N :c"
read position
echo
echo -e "ttT E L E P H O N E :c"
read telephone
echo
echo -e "ttE _ M A L E :c"
read email
echo -e "$namett$positiontt$telephonett$email" >> $FILENAME
echo
echo -e "ttDo 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 "ttPlease 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 "ttLine Deleted!"
;;
n|N|No|NO)
echo
;;
*)
echo -e "ttPlease 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 Linet |"
echo -e "t|t2. Del record by Namet |"
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 "tt Your selection:c"
read selection
echo
case $selection in
1)
echo -e "ttInput Start_Line_Number:c"
read line1
echo
echo -e "ttInput End_Line_Number:c"
read line2
echo
echo -e "ttLine$line1 to Line$line2 are:"
echo
echo -e "t姓 名tt职 位tt 电 话ttt电子邮件"
echo
sed -n ''$line1','$line2'p' $FILENAME |cat -n
echo
echo -e "ttDelete really?[y/n]:c"
read proceed
proceed $proceed sed ''$line1','$line2'd'
;;
2)
echo -e "ttInput Name:c"
read name
echo
echo -e "ttrecord include $name are:"
echo
echo -e "t姓 名tt职 位tt 电 话ttt电子邮件"
echo
grep -w ^$name $FILENAME |cat -n
echo
echo -e "ttDelete really?[y/n]:c"
read proceed
proceed $proceed grep -vw ^$name
;;
3)
echo -e "ttInput Telephone:c"
read telephone
echo
echo -e "ttrecord include $telephone are:"
echo
echo -e "t姓 名tt职 位tt 电 话ttt电子邮件"
echo
grep -w $telephone $FILENAME |cat -n
echo
echo -e "ttDelete really?[y/n]:c"
read proceed
proceed $proceed grep -vw $telephone
;;
4)
echo
show
;;
5)
echo
main
;;
*)
clear
del
esac

echo
echo -e "ttDo 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 "ttPlease input y|Y|yes|Yes|YES or n|N|No|NO"
echo
exit 1
esac
}


show(){
echo
echo -e "t姓 名tt职 位tt 电 话ttt电子邮件"
echo
cat -n $FILENAME
echo
echo -e "ttDo 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 "ttPlease 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 recordt |"
echo -e "t|t4. Exit t |"
echo -e "t--------------------------------"
echo
echo -e "tt Your selection:c"
read selection
echo

case $selection in
1)
add
;;
2)
del
;;
3)
show
;;
4)
exit 1
;;
*)
main
esac
}
main

转载自:http://www.unlinux.com/doc/shell/20051026/259.html

评论】 【加入收藏夹】 【 】 【打印】 【关闭
 *  请尊重我们的劳动,转载请注明出自UnLinux.Com及作者名 * 

※ 相关链接
 ·从 ifconfig 中得到 IP地址  (2005-10-26 00:49:46)
 ·一个把IP地址转化为长整数的脚本  (2005-10-26 00:49:44)
 ·finger统计同ip地址的tty终端数  (2005-10-26 00:49:43)

Copyright © 2005 UnLinux.Com All Rights Reserved