RHCE实验:通过脚本判断用户是否存在
一、实验要求
1、
写一个脚本,使用函数完成 1 、函数能够接受一个参数,参数为用户名; 判断一个用户是否存在 如果存在,
就返回此用户的 shell 和 UID ;并返回正常状态值; 如果不存在,就说此用户不存在;并返回错误状态值
2、
在主程
序中调用函数
二、实验代码
[root@localhost ~]# vim /shell/userms.sh
#!/bin/bashuser() {if id "$1" &>/dev/nullthenecho "`grep ^$1 /etc/passwd | cut -d: -f3,7`"return 0elseecho "$1 does not exist"return 1fi
}
read -p 'please input username:' username
until [ "$username" = "quit" -o "$username" = "exit" -o "$username" = "q" ]
douser $usernameif [ "$?" == 0 ];thenread -p 'please input again:' usernameelseread -p 'no $username,please input again:' usernamefi
done
三、测试结果
(本实验所用软件为MobaXterm)