shell脚本练习题(一)
来源:互联网 发布:matlab 二维数组赋值 编辑:程序博客网 时间:2024/06/06 08:39
写一个脚本
1.设定变量FILE的值为/etc/passwd
2.依次向/etc/passwd中的每个用户问好,并且说出对方的ID是什么
形如:(提示:LINE=wc -l /etc/passwd | cut -d" " -f1
)
Hello,root,your UID is 0.
3.统计一个有多少个用户
方案1:#!/bin/bashFILE="/etc/passwd"LINE=`cat /etc/passwd|wc -l`for i in $(seq 1 $LINE) do NAME=`cat /etc/passwd | awk -F ":" '{printf $1"\n"}'|sed -n ${i}p` 利用awk和sed截取出所需用的值 UI=`cat /etc/passwd | awk -F ":" '{printf $3"\n"}'|sed -n ${i}p` echo Hello,$NAME,your UID is $UIdone echo there are $LINE users
方案2:#!/bin/bashfile="/etc/passwd" LINES=`wc -l $file | cut -d" " -f1` ##利用cut截取出需用的值 for I in `seq 1 $LINES`;do userid=`head -$I $file | tail -1 |cut -d: -f3` username=`head -$I $file | tail -1 |cut -d: -f1` echo "hello $username,your UID is $userid" done echo "there are $LINES users"
阅读全文
0 0
- shell脚本练习题(一)
- shell脚本练习题
- shell脚本练习题
- shell脚本练习题
- shell脚本:练习题
- shell脚本(一)
- shell脚本(一)
- shell 脚本语法 (一)
- shell脚本学习(一)
- shell脚本笔记(一)
- Linux shell 脚本(一)
- shell脚本编程(一)
- shell脚本练习(一)
- shell脚本编程(一)
- shell脚本编程(一)
- shell脚本编写(一)
- shell脚本学习(一)
- shell脚本学习(一)
- roscd: No such package/stack 'beginner_tutorials'
- 从键盘获取3个整型数据
- php 对称加密
- C++ Primer知识系列三:函数基础
- eclipse 使用笔记
- shell脚本练习题(一)
- 在矩阵乘法,为什么 Matlab这么快?
- 介绍GNU中__attribute__机制的网址
- 一个不错的log4j.properties例子
- 统计HDFS文件数量,大小,以及在某范围大小的文件数量
- 大数据系列的默认端口(hbase,hadoop,hived等)
- 热修复——深入浅出原理与实现
- NSIS软件升级包的制作
- Select-DropDownList通过Javascript实现模糊搜索