龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 操作系统 > LINUX系统 >

shell script写的通迅录

时间:2011-03-20 22:37来源:未知 作者:admin 点击:
分享到:
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

  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

精彩图集

赞助商链接