首页 新闻 会员 周边

编写一个名为checking的shell脚本来完成以下功能

0
悬赏园豆:10 [已解决问题] 解决于 2012-07-26 17:25

编写一个名为checking的脚本来完成以下功能:

1、取得参数---用户输入的需要检查用户名
2、测试是否存在阐述
3、如果存在就测试是否存在在/etc/passwd中
4、存在打印:found<输入用户>在/etc/passwd
5、否则打印:no user in sysytem
linuxnewbie的主页 linuxnewbie | 初学一级 | 园豆:177
提问于:2012-07-26 15:28
< >
分享
最佳答案
0

#!/bin/bash
#The script name: checking.sh
#Date: 2012/07/26

$NAME
if test -z $1
then echo "Place enter a username:"
elif fgrep $1 /etc/passwd >/dev/null
then echo "Found $1 in the /ect/passwd file."
else echo "No such $1 on our system."
fi

linuxnewbie | 初学一级 |园豆:177 | 2012-07-26 17:24
其他回答(1)
0

#!/bin/sh
if [ -z $1 ];then
        echo "there is no parameter!"
fi
username=$1
if [ -n `grep $username /etc/passwd` ];
then
        echo "found $username in /etc/passwd"
else
        echo "no user in system"
fi

吾月 | 园豆:160 (初学一级) | 2014-06-10 14:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册