判断用户名的shell脚本

写一个脚本文件,该脚本运行时带用户名作为参数,在/etc/passwd文件中查找用户,如有,则输出“ in the /etc/passwd”;否则输出” no such user on our system”。

#!/bin/bash
read user
n=`cut -d: -f1 /etc/passwd|grep -c "^$user$"`
if [ $n -gt 0 ]
then
echo "$user exists"
else
echo "$user does not exist"
fi
原文地址:https://www.cnblogs.com/khnl/p/12762332.html