19.shell脚本编程(4)

    循环处理文件数据

xin@xin ~/Test $ cat 2.sh
#!/bin/bash
IFS.OLD=$IFS

for entery in `cat /etc/passwd` ; do 
	echo "Values in $entery -"
	IFS=:
	for value in $entery ; do
		echo "    $value"
	done
done
xin@xin ~/Test $ bash 2.sh
2.sh: 行 2: IFS.OLD=: 未找到命令
Values in root:x:0:0:root:/root:/bin/bash -
    root
    x
    0
    0
    root
    /root
    /bin/bash
    break退出循环

    continue退出本轮循环

    循环输出的处理

xin@xin ~/Test $ cat 3.sh
#!/bin/bash
for (( a=1; a < 10; a++ )) ; do
	echo "The number is $a"
done > 123.txt
xin@xin ~/Test $ bash 3.sh 
xin@xin ~/Test $ cat 123.txt 
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
The number is 6
The number is 7
The number is 8
The number is 9
    脚本中$0指程序名,$1-$n指第几个参数,对于多位要使用$(10)

    basename用来获得文件名

   $#脚本运行时参数个数

   ${!#}最后一个参数

   $*将所有参数当成单个参数,$@变量会单独处理每个参

   shift用来移动参数


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值