博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
对每个用户说hello
阅读量:7010 次
发布时间:2019-06-28

本文共 764 字,大约阅读时间需要 2 分钟。

1 #!/bin/bash2 #对每个用户说hello3 #用户数4 Lines=`wc -l /etc/passwd | cut -d' ' -f1`5 6 for P in `seq 1 $Lines`; do7   echo "Hello,`sed -n ""$P"p" /etc/passwd | cut -d: -f1`."8 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`."  fidone

 

转载地址:http://dqttl.baihongyu.com/

你可能感兴趣的文章
HashMap与ConcurrentHashMap的区别(转)
查看>>
ThreadPoolExecutor使用和思考(上)-线程池大小设置与BlockingQueue的三种实现区别
查看>>
图的理解:深度优先和广度优先遍历及其 Java 实现
查看>>
Linux/Unix shell 监控Oracle告警日志(monitor alter log file)
查看>>
Linux之 find之 ctime,atime,mtime
查看>>
Asp.net mvc 集成Autofac和FluentValidation
查看>>
WinForm企业应用框架设计【一】界限划分与动态创建WCF服务(no svc!no serviceActivations!)...
查看>>
sharepoint 页面使用javascript出错解决办法
查看>>
程序员究竟该如何提高效率【转】
查看>>
UVA 10056 What is the Probability ?
查看>>
DotNet4应用程序打包工具->升级版【三】宿主程序分析+全部源码下载
查看>>
WMI事件监控
查看>>
pku 2186 Popular Cows (tarjan缩点)
查看>>
c关键字控制语句运算符小结
查看>>
初学Oracle的笔记(1)——基础内容(实时更新中..)
查看>>
(转)Ogre 安装 配置 问题
查看>>
【转】清理浮动的全家
查看>>
ZJOI2006 物流运输trans
查看>>
WinForm编程数据视图之DataGridView浅析(续)
查看>>
vim中实现括号和引号自动补全
查看>>