功能:判断输入的用户名是否存在与/etc/passwd中
#!/bin/bash
if [ $# -le 0 ];then
echo "Please input the right arg"
else
i=`cat /etc/passwd | cut -f1 -d':' | grep -w "$1" -c `
if [ $i -le 0 ];then
echo "User $1 is not in the passwd"
else
echo "User $1 is in the passwd"
fi
fi
本文介绍了一个简单的bash脚本,用于检查指定的用户名是否存在于系统的 /etc/passwd 文件中。该脚本首先验证输入参数的存在性,然后通过一系列命令如 cat、cut 和 grep 来搜索目标用户名,并最终返回用户是否存在的确切信息。
142

被折叠的 条评论
为什么被折叠?



