# 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. 修改 Vultr 登录密码

    Debian,Ubuntu 访问控制台,打开在线 Console,点击右上角的 “Send CtrlAltDel”,按 ESC 键启动 GRUB boot prompt. 按 e 编辑第一启动项.按 ...

  2. django之关联field 描述子

    """Accessors for related objects. When a field defines a relation between two models, ...

  3. python xlrd xlwt

    1.什么是xlrd模块? 2.为什么使用xlrd模块? 3.怎样使用xlrd模块? 1.什么是xlrd模块? ♦python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel, ...

  4. Javascript 京东轮播图

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  5. Linux OS7 常用

    查看防火墙状态: firewall-cmd --state;停止firewall: systemctl stop firewalld.service;禁止firewall开机启动:systemctl ...

  6. 每日一练之大整数加法(P1255 数楼梯)

    走楼梯走一步还是两步的问题其实就是斐波那契数列(F(n)=F(n-1)+F(n-2),而在int型范围内存在45个相异的数,题干说明楼梯总数可以为5000,则考虑使用字符串进行存储.当两个数相加产生进 ...

  7. [Linux]系统管理: 进程管理(ps/top/pstree/kill/pkill), 工作管理, 系统资源查看, 系统定时任务

    进程管理:查看与终止 进程查看 1. 进程是正在执行的程序或命令. 2. 进程管理的作用: 判断服务器健康状态, 查看系统中所有进程 杀死进程 3. 查看系统中所有进程 ps aux    # 查看系 ...

  8. JQuery+formValidator实现表单验证

    <!-- 需求: 用户注册页面要有用户名.密码.确认密码.邮箱 用户名文本框:用户名不能为空,且必须为数字与字母的6到12位的组合 密码框:密码不能为空,最少6位,包括至少1个大写字母,1个小写 ...

  9. file常用功能

    构造方法 File(String pathname):将指定的路径名转换成一个File对象 File f = new File("D:\\a\\b.txt"); File(Stri ...

  10. python中类中的@property

    @property考察 Student 类: class Student(object): def __init__(self, name, score): self.name = name self ...