bash while循环不会自行停止 [英] bash while loop won't stop itself

查看:60
本文介绍了bash while循环不会自行停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个简单的脚本,该脚本想创建一堆帐号,它应该包含两个值:起始帐号和要创建的帐号数.逐步增加帐号.例如:

I got this simple script that is suppose to create a bunch of account numbers, it should take in two values: starting account number and how many accounts to create. Incrementing the account number as we go. So for example:

./pre_v_test.sh 123 3应该给

./pre_v_test.sh 123 3 should give

123

124

125

现在它做到了,只有一个问题:完成后无法停止.结果看起来像这样:

Right now it does that, with just one problem: it can't stop after it is done. the results look something more like this:

....
Writing subsriber: 102145
lalala
Writing subsriber: 102145
lalala
Writing subsriber: 102145
lalala
....

您明白了.

下面是代码:

#!/bin/bash

i_loop="0"
while [ $i_loop -lt $2 ]
do

i_subscriber=`expr $1 + $i_loop`

echo Writing subsriber: $i_subscriber

#actual account details here, not relevent to the question 

echo "lalala"
done

我在这里浏览了while循环的示例( http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_02.html ),但是对于我一生来说,我看不出有什么区别,是什么使他的工作和我的失败?另外,从两个月前开始,该脚本即可正常工作.和现在之间的唯一区别是,上次它是在实际SUSE上,而这次是在vmware上是在SUSE上.

I looked through this example of a while loop here (http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_02.html) but for the life of me I can't spot the difference, what made his work and mine fail? Also, as of two months ago this script was working. the only difference between the and now is that last time it was on a real SUSE and this time it is on SUSE on vmware.

谢谢大家戴维

推荐答案

您没有递增变量:

#!/bin/bash

i_loop=0

while [ $i_loop -lt $2 ]
do

i_subscriber=`expr $1 + $i_loop`

echo Writing subsriber: $i_subscriber

i_loop=`expr $i_loop + 1`

done

这篇关于bash while循环不会自行停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆