#! /bin/sh
DBASE="$HOME/phonebook"
checkrun() {
while [ -f running ]
do
sleep 2
done
touch running
}
adding() {
if [ -s $$.add ]
then
checkrun
touch running
cat $$.add >> $DBASE 2> /dev/null
rm $$.add 2> /dev/null
rm running
fi
}
deleting() {
if [ -s $$.del ]
then
checkrun
touch running
echo "w" >> $$.del
ed $DBASE < $$.del 2> /dev/null
rm $$.del
rm running
fi
}
editing() {
if [ -s $$.edit ]
then
checkrun
touch running
echo "w" >> $$.edit
ed $DBASE < $$.edit 2> /dev/null
rm $$.edit
rm running
fi
}
while :
do
clear
echo "ÀüȹøÈ£ºÎ
a : ÀÔ·Â
d : »èÁ¦
e : ¼öÁ¤
s : °Ë»ö
v : Ãâ·Â
[enter] : Á¾·á
¿øÇϽô ÀÛ¾÷Àº ?(a,d,e,s,v,[enter]) :\c"
read RSP
case $RSP in
"")
exit 0
;;
a|A|¤±)
ASK=y
while [ "$ASK" = "y" -o "$ASK" = "Y" ]
do
echo "À̸§ =\c"
read NAME
if [ "$NAME" = "" ]
then break
fi
echo "Á÷¾÷ =\c"
read OCCU
echo "ÀüȹøÈ£ =\c"
read NUM
echo "$NAME $OCCU $NUM" >> $$.add
echo "continue? (y/n) (default=y)\c"
read ASK
if [ "$ASK" = "" ]
then ASK=y
fi
done
adding &
;;
d|D)
ASK=y
while [ "$ASK" = "y" -o "$ASK" = "Y" ]
do
echo "»èÁ¦ÇÒ À̸§ =\c"
read NAME
if [ "$NAME" = "" ]
then break
fi
echo "/$NAME/d" >> $$.del
echo "continue ? (y/n) (default=y)\c"
read ASK
if [ "$ASK" = "" ]
then ASK=y
fi
done
deleting &
;;
e|E)
ASK=y
while [ "$ASK" = "y" -o "$ASK" = "Y" ]
do
echo "¼öÁ¤ÇÒ À̸§ =\c"
read NAME
if [ "$NAME" = "" ]
then break
fi
echo "Á÷¾÷ =\c"
read OCCU
echo "ÀüȹøÈ£ =\c"
read NUM
echo "/$NAME/c" >> $$.edit
echo "$NAME $OCCU $NUM" >> $$.edit
echo . >> $$.edit
echo "continue? (y/n) (default =y )\c"
read ASK
if [ "$ASK" = "" ]
then ASK=y
fi
done
editing &
;;
s|S)
ASK=y
while [ "$ASK" = "y" -o "$ASK" = "Y" ]
do
echo "°Ë»öÇÒ À̸§=\c"
read NAME
if [ "$NAME" = "" ]
then NAME=.*
fi
echo "°Ë»öÇÒ Á÷¾÷ =\c"
read OCCU
if [ "$OCCU" = "" ]
then OCCU=.*
fi
echo "°Ë»öÇÒ ÀüȹøÈ£ =\c"
read NUM
if [ "$NUM" = "" ]
then NUM=.*
fi
echo "---------------------------------------------"
echo "À̸§ Á÷¾÷ ÀüȹøÈ£ "
echo "---------------------------------------------"
grep -i "$NAME" $DBASE | grep -i "$OCCU" |grep -i "$NUM"
echo "---------------------------------------------"
echo "continue? (y/n) (default=n)\c"
read ASK
if [ "$ASK" = "" ]
then ASK=n
fi
done
;;
v|V|¤½) echo " ÀüÈ ¹øÈ£ºÎ"
echo "---------------------------------------------"
echo "À̸§ Á÷¾÷ ÀüȹøÈ£"
echo "---------------------------------------------"
more $DBASE
echo "---------------------------------------------"
echo "¿£Å͸¦ Ä¡½Ã¿À"
read RSP
;;
*)
echo "¸í·É¾îÀÇ ÀÔ·ÂÀÌ À߸øµÆ½À´Ï´Ù"
;;
esac
done
|