- 论坛徽章:
- 0
|
自己编的一个通讯录系统(简陋了点)
show脚本,用来查询的:
function answer ()
{
read
case $REPLY in
y|Y|[Yy][Ee][Ss] ) show ;;
n|N|[Nn][Oo] ) menu ;;
* ) exit 0;;
esac
}
function showname ()
{
showname=`awk -F: -v new=$name '{ if ( $1 == new ) print $0; }' addressbook | awk -F: '{ printf "%-10s%s\n%-10s%s\n%-10s%s\n%-10s%s\n%-10s%s\n%-10s%s\n\n", "Name: ", $1, "E-mail: ",$2, "Address: ", $3, " hone Number: ", $4, "Moblie Phone Number: ", $5, "Other Messages: ", $6 ; }' `
}
function showall ()
{
awk -F: '{ printf "%-10s%s\n%-10s%s\n%-10s%s\n%-10s%s\n%-10s%s\n%-10s%s\n\n", "Name: ", $1, "E-mail: ",$2, "Address: ", $3, " hone Number: ", $4, "Moblie Phone Number: ", $5, "Other Messages: ", $6 ; }' addressbook
}
function show ()
{
echo -ne "\33[33mWhose data you want to know ? \n\33[34mType his or her name directly ( Type "all" for check out for all people! ): \33[0m"
read name
if [ -f "addressbook" ]
then
if [ $name == "all" ]
then
showall
echo -e "\33[33mType "y" to check a person's data, and "n" to the main menu, other keys will exit!\33[0m"
answer
else
showname
if [ -z "$showname" ]; then
echo -e "The person you want to know does not exist! \nDo you want to try again or check out other's data? [y or n ,and any other key will exit! ]"
answer
else
echo -e "$showname"
echo Do you want to check another person\'s data? [y or n ,and any other key will exit! ]
answer
fi
fi
else echo -e "\33[31mThe addressbook isn't exist!\33[0m"; menu
fi
} |
|