我有一个循环的问题,我在我的脚本中使用如下:
while read LINE do { } done
但是问题是每次我在运行脚本的时候都按下input,而且应该这样做50000次! 我怎么能改变这个自动运行的循环?
我能计算我的文件的长度:lenght =`wc -l <myfile然后使用它? 或者更好的解决scheme?
你可以使用for循环?
for i in {1..5} do echo "I have $i bottle(s) of Mountain Dew" done I have 1 bottle(s) of Mountain Dew I have 2 bottle(s) of Mountain Dew I have 3 bottle(s) of Mountain Dew I have 4 bottle(s) of Mountain Dew I have 5 bottle(s) of Mountain Dew
你甚至可以倒退!
for i in {5..1} do echo "I have $i bottle(s) of Mountain Dew" done I have 5 bottle(s) of Mountain Dew I have 4 bottle(s) of Mountain Dew I have 3 bottle(s) of Mountain Dew I have 2 bottle(s) of Mountain Dew I have 1 bottle(s) of Mountain Dew
your_script <5000_lines.dat
在你的时候,你应该检查“不是EoF”,并把read入循环。
尝试这个:
yes "" | while ....
这发送了一个你的while-body可以使用的换行符。