脚本1,要点切片、bc、while读取文件
要求读取以下信息: 输出以下格式:
host1 host1 0 001
host2 host1 1 002
host3 host2 0 003
…… host2 1 004
......
shell脚本内容:
知识点:
循环
done<namefile 将namefile里的内容传给循环while,read 的就是namefile
切片
${var:offset:number} 取var变量中的字符串中的字符,offset自左往右第几个字符开始默认0为第一个,number为要取的个数
示例:${num:1:3} 左边第1个字符开始,取3个字符,结果为001
bc
是一种支持任意精度的交互执行的计算器语言
示例:echo "3+4" | bc 输出结果:7
循环命令:
case ...in
...)do something here;;
esac
下面是一个例子:
#!/bin/sh
ftype=`file "$1"`
case "$ftype" in
"$1: Zip archive"*)
unzip "$1" ;;
"$1: gzip compressed"*)
gunzip "$1" ;;
"$1: bzip2 compressed"*)
bunzip2 "$1" ;;
*) echo "File $1 can not be uncompressed with smartzip";;
esac
脚本含义:自动解压bZip2,gzip和zip类型的文件