编辑推荐:
linuxfree参数详解
Linux操作系统下配置无线连接
加固Linux服务器的绝招
pl文件:
#!/bin/bash
#read n p
PL='phonelist'
if [ $1 == 'c' ]
then
rm -f $PL
touch $PL
echo 'cleaned all persons'
exit 0
fi
if [ $# -eq 1 ] && [ $1==v ]
then
cat $PL
exit 0
fi
if [ $# -ne 2 ]
then
if [ $# -eq 3 ] && [ $1 == 'm' ]
then
#read -p 'put the person name:' n
#read -p 'change name to:' nn
#read -p 'change number to:' np
cat $PL|grep -v $2>$PL
echo -e $2'\t'$3>>$PL
cat $PL
else
echo 'person name and phone number must not be empty!'
fi
exit 1
fi
if [ $1 == 'd' ]
then
cat $PL|grep -v $2>$PL
echo 'delete person ' $2' successfully!'
else
echo -e $1'\t'$2>>$PL
echo 'succesfully add a phone number'
cat $PL|grep $1
fi
exit 0
运行:
1 ./pl 伟子 13699520723
添加联系人伟子,手机号码为13699520723
2 ./pl d 伟子
删除联系人伟子
3 ./pl m 伟子 15866432516
修改联系人伟子的手机号码为15866432516