首页 > 其他 > 详细

2014-10-17(脚本练习)

时间:2014-10-17 15:44:45      阅读:136      评论:0      收藏:0      [点我收藏+]

写一个脚本:
1、使用函数实现:
   判断一个用户是否存在,用户名通过参数传递而来;
   如果存在,就显示此用户的shell和UID
   如果不存在,就说此用户不存在;
2、提示用户输入用户名,而后将其传递给上面的函数;
3、判断结束后不退出,而是提示用户可继续输入其它用户名,或输入(q)退出;


#!/bin/bash
##Author: Yang Jing
##time: 2014-10-17
##description:  for judge the user exists or not

user_exists() {
        read -p "please input a user name: " User
        [ $User == "q" ] && exit 0
        cat /etc/passwd | grep "^$User:" &> /dev/null
        RETRAL=$?
        if [ $RETRAL -ne 0 ];then
                echo " no such user $User"
        else
                echo "$User uid is `id -u $User`"
                echo "$User shell is `echo $RETRAL | cut -d: -f 7`"
        fi

}

while true;do
        user_exists
done

本文出自 “每一步都是新的起点!^_^” 博客,谢绝转载!

2014-10-17(脚本练习)

原文:http://90112526.blog.51cto.com/6013499/1565087

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!