实验要求:
#!/bin/bash
if [ $# = 1 ]
then
num=$(cut -d: -f1 /etc/passwd | grep $1 | wc -l)
if [ num = 0 ]
then
echo No such user on our system
else
echo "Found $1 in the /etc/passwd file"
fi
else
echo wrong para
fi
另一种方法:
#!/bin/bash
usr=$(cut -d : -f 1 /etc/passwd)
haveUser=0
for para in $usr
do
if [ "$1" = "$para" ]
then
echo $para
haveUser=1
echo "Found $1 in the /etc/passwd file."
fi
done
if [ "$haveUser" = 0 ]
then
echo No such user on our system
fi