shell脚本学习-练习写一个脚本1
2024-10-10 04:58:08
# 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
最新文章
- Android 自定义View
- 关于Eclipse的unsupported major minor version 51.0 错误
- SQL行转列
- Jquery 学习二
- 暑假集训(2)第二弹 ----- The Suspects(POJ1611)
- GWT(Google Web Tookit) Eclipse Plugin的zip下载地址(同时提供GWT Designer下载地址)
- Mysql服务启动问题
- Matlab中K-means聚类算法的使用(K-均值聚类)
- 使用log4j日志-配置载入问题
- 业余草推荐18个Java开源免费的CMS系统
- 浅谈CSS3动画的凌波微步--steps()
- Hadoop:Hadoop简介及环境配置
- Qt快速入门第三版下载
- 最小可用id
- 关于mysql存储过程中传decimal值会自动四舍五入的这个坑
- ES6躬行记(7)——代码模块化
- Learning-Python【21】:Python常用模块(4)—— re、logging、hashlib、subprocess
- ionic tab显示到顶部去了
- SearchContextMissingException[No search context found for id [1545782]]
- 【javascript】内存泄露及其解决办法