# 1.依次展示/etc/passwd中的用户名和UID。格式如:Hello,$USER,your UID is $UID.

# 2.统计一个有多少个用户

#!/bin/bash
#Program Description:
#Author: Created by ctu_lzq
#Date: //
FILE="/etc/passwd"
LINES=`cat $FILE |wc -l`
#for i in `seq $LINES`;
for ((i=;i<=$LINES;i++));
do
userlist=`sed -n "$i""p" $FILE|awk -F: '{print $1}'`
uidlist=`sed -n "$i""p" $FILE|awk -F: '{print $3}'`
echo "Hello,$userlist,your UID is $uidlist"
done
echo "there are $LINES users"
结果如:
[root@study learnshell]# bash test.sh
Hello,root,your UID is 0
Hello,bin,your UID is 1
Hello,daemon,your UID is 2
Hello,adm,your UID is 3
Hello,lp,your UID is 4
Hello,sync,your UID is 5
Hello,shutdown,your UID is 6
Hello,halt,your UID is 7
Hello,mail,your UID is 8
Hello,uucp,your UID is 10
Hello,operator,your UID is 11
Hello,games,your UID is 12
Hello,gopher,your UID is 13
Hello,ftp,your UID is 14
Hello,nobody,your UID is 99
Hello,dbus,your UID is 81
Hello,usbmuxd,your UID is 113
Hello,rpc,your UID is 32
Hello,rtkit,your UID is 499
Hello,avahi-autoipd,your UID is 170
Hello,vcsa,your UID is 69
Hello,abrt,your UID is 173
Hello,rpcuser,your UID is 29
Hello,nfsnobody,your UID is 65534
Hello,haldaemon,your UID is 68
Hello,ntp,your UID is 38
Hello,apache,your UID is 48
Hello,saslauth,your UID is 498
Hello,postfix,your UID is 89
Hello,gdm,your UID is 42
Hello,pulse,your UID is 497
Hello,sshd,your UID is 74
Hello,tcpdump,your UID is 72
Hello,mysql,your UID is 27
Hello,nginx,your UID is 496

  

shell脚本学习-练习写一个脚本1的更多相关文章

  1. SHELL脚本学习-练习写一个脚本4

    #编写一个脚本时,自动生成”#!/bin/bash”这一行和相关注释信息. 把以下的代码保存为一个sh文件,比如test.sh , 新建脚本是使用  bash test.sh newfile 即可. ...

  2. shell脚本学习-练习写一个脚本2

    # 1.依次展示/var目录下的对象,并说明是文件或者目录.格式如:Hello,$file. # 2.统计一个有多少个文件. #!/bin/bash #Program Description: #Au ...

  3. SHELL脚本学习-练习写一个脚本3

    #通过ping命令测试192.168.1段的所有主机是否在线,如果在线就显示is up并显示蓝色,如果不在线就显示is down. #!/bin/bash #Program Description: ...

  4. Shell 命令行,写一个自动整理 ~/Downloads/ 文件夹下文件的脚本

    Shell 命令行,写一个自动整理 ~/Downloads/ 文件夹下文件的脚本 在 mac 或者 linux 系统中,我们的浏览器或者其他下载软件下载的文件全部都下载再 ~/Downloads/ 文 ...

  5. Python 脚本如何执行另一个脚本

    关于Python 脚本如何执行另一个脚本,可以使用os.system()来实现 os.system()的参数: 执行的命令 +执行的内容 举例说明: (1)显示当前文件夹下的全部目录和文件夹 os.s ...

  6. python 学习笔记 12 -- 写一个脚本获取城市天气信息

    近期在玩树莓派,前面写过一篇在树莓派上使用1602液晶显示屏,那么可以显示后最重要的就是显示什么的问题了. 最easy想到的就是显示时间啊,CPU利用率啊.IP地址之类的.那么我认为呢,假设可以显示当 ...

  7. 写一个脚本,自动启动tomcat

    我的服务器是使用tomcat的,时不时tomcat的进程会突然结束掉,不知道为什么,从日志上看也没有任何可疑之处,貌似就这样突然没了,接下来的日志都是重新启动tomcat之后打印的了.原因找不到,但要 ...

  8. CBrother脚本10分钟写一个拯救“小霸王服务器”的程序

    CBrother脚本语言10分钟写一个拯救“小霸王服务器”的程序 到了一家新公司,接手了一坨c++服务器代码,到处内存泄漏,这服务器没有数据库,挂了后重启一下就好了,公司就这么凑活着用了几年了,定时重 ...

  9. Shell脚本中调用另外一个脚本的方法

    (转载): 在Linux平台上开发,经常会在console(控制台)上执行另外一个脚本文件,经常用的方法有:./my.sh 或 source my.sh 或 . my.sh:这三种方法有什么不同呢?我 ...

随机推荐

  1. Git上传本地代码

    Git  add  .将本地文件上传至缓冲区 git   commit  -m  'project  init'  将代码上传至本地仓库 Git   push   将本地的代码传至线上(码云) git ...

  2. 将String类型的json字符串转换成java对象

    1,import com.fasterxml.jackson.databind.ObjectMapper; ObjectMapper mapper = new ObjectMapper(); Mycl ...

  3. MYSQL1

    一:对查询就行优化 避免全表查询 1.首先考虑在where及order by 列上建立索引 2.where子句   LIKE  '%abc%' 前置%   引擎放弃使用索引而进行全表扫描 3.wher ...

  4. 18Linux-LNMP-Linux就该这么学

    LNMP 编译环境包: [root@linuxprobe ~]# yum install -y apr* autoconf automake bison bzip2 bzip2* compat* cp ...

  5. Python module ---- re

    Python 的 re 模块(Regular Expression 正则表达式)提供各种正则表达式的匹配操作,在文本解析.复杂字符串分析和信息提取时是一个非常有用的工具.python的re模块,在绝大 ...

  6. 微信小程序代码大全 - 小程序开发福利

    小程序QQ交流群:131894955 小程序开发文档(Wepy) 小程序商城源码下载(weixin-app-shop) 小程序官网源码下载(weixin-app-cms) 微信管家平台JAVA版开源下 ...

  7. 如何在Chrome中导入和导出密码

    如果想让 Chrome 支持密码导入和导出,需要先在地址栏中执行  chrome://flags/#password-import-export  将该功能启用并重启浏览器才能生效. 浏览器重启完成后 ...

  8. 如何监控Redis性能指标(译)

    Redis给人的印象是简单.很快,但是不代表它不需要关注它的性能指标,此文简单地介绍了一部分Redis性能指标.翻译过程中加入了自己延伸的一些疑问信息,仍然还有一些东西没有完全弄明白.原文中Metri ...

  9. position:fixed失效情况

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. linux dns域名缓存

    在linux服务器中,我们 总会设置一个dns做域名解析 一般来说dns的缓存是不会造成多大的困扰,但是,有时候会遇到dns解析导致网络不能正常访问 在linux中,有一个缓存服务,我们可以重启这个来 ...