码迷,mamicode.com
首页 > 系统相关 > 详细

shell练习题1

时间:2016-08-16 14:55:46      阅读:435      评论:0      收藏:0      [点我收藏+]

标签:1

练习一:写一个脚本
       1.设定变量FILE的值为/etc/passwd
       2.依次向/etc/passwd中的每个用户问好,并且说出对方的ID是什么
        形如:(提示:LINE=`wc -l /etc/passwd | cut -d" " -f1`)
         Hello,root,your UID is 0.
       3.统计一个有多少个用户
程序如下:
#!/bin/bash
file="/etc/passwd"
line=` wc -l $file|cut -d" " -f1 `
for i in ` seq 1 $line `;do
userid=` head -$i $file| tail -1 |awk -F ":" ‘{print $3}‘`
username=` head -$i $file| tail -1 |awk -F ":" ‘{print $1}‘`
echo "hello,$username!your uid is $userid"
done
echo "There are $line users"

本文出自 “linux运维” 博客,转载请与作者联系!

shell练习题1

标签:1

原文地址:http://xxr007.blog.51cto.com/10602872/1839167

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!