#!/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 th passwd"
else
echo "user $1 is in the passwd"
fi
fi
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 th passwd"
else
echo "user $1 is in the passwd"
fi
fi
本文介绍了一个简单的bash脚本,用于检查特定用户名是否存在于Linux系统的/etc/passwd文件中。此脚本通过命令行输入用户名作为参数,然后读取passwd文件并判断该用户名是否存在。
1364





