首页 > 系统服务 > 详细

shell---practice1

时间:2016-01-11 18:31:28      阅读:186      评论:0      收藏:0      [点我收藏+]

要求:

1.设定变量FILE的值为/etc/passwd

2.依次向/etc/passwd中的每个用户问好,并且说出对方的ID是什么。

 举例:Hello,root,your UID is 0.

3.统计一个有多少个用户

#!/bin/bash 
#File: hello_user.sh
#Date: 2016-01-11
file="/etc/passwd"     //将文件赋值给变量
lines=`wc -l $file | cut -d ‘ ‘ -f 1`     //统计行数
for i in `seq 1 $lines`     //将i做循环
do
        uid=`sed -n "$i"p $file | awk -F : ‘{print $3}‘`     //取出uid
        user=`sed -n "$i"p $file | awk -F : ‘{print $1}‘`    //取出user
        echo "Hello, $user, your UID is $uid."
done
echo "There are $num users!"     //统计用户


本文出自 “经验来自痛苦” 博客,谢绝转载!

shell---practice1

原文:http://strike.blog.51cto.com/10311680/1733848

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