对每个用户说hello
2016-08-14 19:56
162 查看
#!/bin/bash #对每个用户说hello #用户数 Lines=`wc -l /etc/passwd | cut -d' ' -f1` for P in `seq 1 $Lines`; do echo "Hello,`sed -n ""$P"p" /etc/passwd | cut -d: -f1`." done
扩展:
1、设定变量FILE的值为/etc/passwd
2、依次向/etc/passwd中的每个用户问好,并显示对方的shell,形如:
Hello, root, your shell: /bin/bash
3、统计一共有多少个用户
提示:for I in `seq 1 $LINES`; do echo "Hello, `head -n $I /etc/passwd | tail -1 | cut -d: -f1`"; done
只向默认shell为bash的用户问声好
#!/bin/bash #对每个用户说hello #用户数 Lines=`wc -l /etc/passwd | cut -d' ' -f1` echo "Total user $Lines." echo "user's shell is /bin/bash:" for P in `seq 1 $Lines`; do if [ `sed -n ""$P"p" /etc/passwd | cut -d: -f7` == "/bin/bash" ]; then echo "$P Hello,`sed -n ""$P"p" /etc/passwd | cut -d: -f1`,your shell is `sed -n ""$P"p" /etc/passwd | cut -d: -f7`." fi done
相关文章推荐
- 伊吹萃香 纪中2556 分层图+spfa
- 配置Hadoop2.xx的高可用(Hadoop2.0 HA)
- 测试、Sqlit、ListView、对话框
- WebSocket API HTML5规范翻译(部分)
- eclipse调试方法详解
- 各种异常汇总
- 买鱼杂感
- 0814牛客网总结
- C和C++混合编程
- 一个IT人成功的背后!
- JZOJ.4693【NOIP2016提高A组模拟8.14】疯狂的火神
- DTMF的原理分析
- 串的抽象数据类型ADT 定义串的一些操作
- 我遇到的微服务的Bean管理bug
- Vitamio视频在小米5手机无法播放问题
- IOS中NSOperation是实现多线程
- POJ 3669 Meteor Shower(BFS)
- 减低页面加载时间的方法
- [CCPC2016]网赛部分比赛代码
- Opencv图像识别从零到精通(27)---grabcut