IBM的一道Shell脚本笔试题

问题:请写出Shell脚本,将文件a中的内容加到文件b的末尾,每次停10秒,循环1000次。

分析:这道题将Shell中的变量定义、循环、判断、文件I/O等知识综合起来考,以下是我写的Shell脚本。

#!/bin/sh #Bourne Shell
i=1000 #Define couter i equal to 1000
while [ $i -ne 0 ] #If couter i is not equal to 0, then do loop.
do #Loop
  cat < a >> b #Read the Content of file a, and add them to the end of file b.
  i=`expr $i - 1` #i--. I use back quotation mark, which is at same button with ~.
  sleep 10 #Wait for 10 seconds
done

这里sleep 10不用加后台执行符号“&”,否则执行不正确。

文件a的内容我写了一行:OK!

文件b的内容我写了两行,结果是1002行。

运行结果如下图:



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值