shell通讯录(3)
来源:互联网 发布:淘宝店铺保修靠谱吗 编辑:程序博客网 时间:2024/06/06 04:56
#!/bin/bash
# delperson
# del a person from addressbook
# args:$1-> name of person to delete
#get the helper function
. /home/addressbook/libComm.sh
PATH=/bin:/usr/bin
if [ $# -lt 1 ];then
printUSAGE "`basename $0 ` name "
exit 1
fi
MYADDRESSBOOK="/home/addressbook/addressbook"
if [ ! -f "$MYADDRESSBOOK" ];then
printERROR "$MYADDRESSBOOK does not exists, or is not a file"
exit 1
fi
#temp file location
TMPF1=/home/addressbook/apupdate.$$
TMPF2=/home/addressbook/abdelets.$$
touch $TMPF1 $TMPF2;
doCleanUp(){
rm "$TMPF1" "$TMPF1.new" "$TMPF2" 2>/dev/null
}
Failed() {
if [ "$1" -ne 0 ];then
shift
printERROR $@
doCleanUp
exit 1
fi
}
cp "$MYADDRESSBOOK" "$TMPF1";
# 2>/dev/null
Failed $? "could not make a backup of the address book"
grep "$1" "$TMPF1" > "$TMPF2";
# 2>/dev/null
Failed $? " no matches found"
# prompt the user for each entry that was found
#exec 5<"$TMPF2"
for LINE in `cat $TMPF2`
# while read LINE <&5
do
#display each line formatted
echo "$LINE" | awk -F: '{
printf "%-10s %s\n%-10s %s\n%-10s %s\n%-10s %s",
"Name:",$1,"Email:",$2,"Address:",$3,"Phone:",$4;
}'
#prompt to delete
promptYESNO "delete this entry" "n"
echo 'yesno=' $YESNO
if [ "$YESNO" = "y" ];then
grep -v "$LINE" "$TMPF1" > "$TMPF1.new" 2>/dev/null
Failed $? "unable to update the address book"
# replace the old file
mv "$TMPF1.new" "$TMPF1" 2>/dev/null
Failed $? "unable to update the address book"
fi
done
#exec 5<&-
#save the original version
mv "$MYADDRESSBOOK" "$MYADDRESSBOOK".bak 2>/dev/null
Failed $? "unable to update the address book"
#replace the original with the edited version
mv "$TMPF1" "$MYADDRESSBOOK" 2>/dev/null
Failed $? "unable to update the address book"
#clean up
doCleanUp
exit $?
# delperson
# del a person from addressbook
# args:$1-> name of person to delete
#get the helper function
. /home/addressbook/libComm.sh
PATH=/bin:/usr/bin
if [ $# -lt 1 ];then
printUSAGE "`basename $0 ` name "
exit 1
fi
MYADDRESSBOOK="/home/addressbook/addressbook"
if [ ! -f "$MYADDRESSBOOK" ];then
printERROR "$MYADDRESSBOOK does not exists, or is not a file"
exit 1
fi
#temp file location
TMPF1=/home/addressbook/apupdate.$$
TMPF2=/home/addressbook/abdelets.$$
touch $TMPF1 $TMPF2;
doCleanUp(){
rm "$TMPF1" "$TMPF1.new" "$TMPF2" 2>/dev/null
}
Failed() {
if [ "$1" -ne 0 ];then
shift
printERROR $@
doCleanUp
exit 1
fi
}
cp "$MYADDRESSBOOK" "$TMPF1";
# 2>/dev/null
Failed $? "could not make a backup of the address book"
grep "$1" "$TMPF1" > "$TMPF2";
# 2>/dev/null
Failed $? " no matches found"
# prompt the user for each entry that was found
#exec 5<"$TMPF2"
for LINE in `cat $TMPF2`
# while read LINE <&5
do
#display each line formatted
echo "$LINE" | awk -F: '{
printf "%-10s %s\n%-10s %s\n%-10s %s\n%-10s %s",
"Name:",$1,"Email:",$2,"Address:",$3,"Phone:",$4;
}'
#prompt to delete
promptYESNO "delete this entry" "n"
echo 'yesno=' $YESNO
if [ "$YESNO" = "y" ];then
grep -v "$LINE" "$TMPF1" > "$TMPF1.new" 2>/dev/null
Failed $? "unable to update the address book"
# replace the old file
mv "$TMPF1.new" "$TMPF1" 2>/dev/null
Failed $? "unable to update the address book"
fi
done
#exec 5<&-
#save the original version
mv "$MYADDRESSBOOK" "$MYADDRESSBOOK".bak 2>/dev/null
Failed $? "unable to update the address book"
#replace the original with the edited version
mv "$TMPF1" "$MYADDRESSBOOK" 2>/dev/null
Failed $? "unable to update the address book"
#clean up
doCleanUp
exit $?
- shell通讯录(3)
- shell 通讯录(1)
- shell通讯录(2)
- shell 通讯录(4)
- iOS 定制手机通讯录(3)
- 通讯录开发学习3
- 通讯录(AddressBook)3
- pro-- 通讯录3-Edit
- 通讯录项目3
- DEMO:通讯录(一)
- DEMO:通讯录(二)
- DEMO:通讯录(三)
- DEMO:通讯录(四)
- DEMO:通讯录(五)
- 个人通讯录(-登录)
- 通讯录(33)
- 通讯录(C语言)
- 通讯录(C语言)
- 今天就是玛雅传说中的世界末日了,你在想些什么?
- PBB-TE分段保护的关键技术
- C++第17周项目2——用指针玩字符串(4)统计单词数
- shell通讯录(2)
- 设计模式(五)----- 原型模式(Prototype)----(JAVA版)
- shell通讯录(3)
- Spring Servlet3 扩展模块笔记
- C++第17周项目2——用指针玩字符串(5)去前导空格
- Lamp管理
- shell 通讯录(4)
- php与mysql使用注意事项
- cocos2d-x与cocos2d-iphone+objc的区别
- CvMemStorage 内存储存器
- android Dialog布局显示已打开的应用程序