gmdzxx 发表于 2018-8-30 08:39:27

shell-用grep查看输入的参数是否在/etc/passwd中

  编写脚本:
  #!/bin/bash
  #####用grep查看输入的参数是否在/etc/passwd中
  #####在,则输出keywords exits,否则输出didn't find keywords
  #####次参数既可以为字母。也可以为字符串、数字
  echo "please input the keywords: "
  read -r x
  if grep $x /etc/passwd > /dev/null
  then
  echo "The keywords $x exits!"
  else
  echo "didn't find $x"
  fi
  给脚本passwd加可运行权限
  chmod +x passwde
  运行脚本:./ passwd
  注:除了在/etc/passwd中查看,读者还可以根据自己的需要,更改文件

页: [1]
查看完整版本: shell-用grep查看输入的参数是否在/etc/passwd中