击而在DO循环语法错误 [英] Bash while loop syntax error in do
本文介绍了击而在DO循环语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试做做一个简单的计数器:
I´m trying do do a simple counter:
max=100
count=1
while [[ $count -le $max]]
do
echo "$count"
((count++))
done
这让我在有条件的前pression语法错误附近做。
This gives me a syntax error in conditional expression near do.
What's我的问题? (可能是明显的东西)
What´s my issue? (probably something obvious)
我们的想法是再提高最大
100至200等中的优势循环,所以我会得到一个新的文件与Python程序来处理100行每一次,但that's这里无关紧要。
The idea is then to raise the max
from 100 to 200 and so forth in a superior loop so I will get a new file to manipulate with a python program 100 lines each time, but that´s irrelevant here.
推荐答案
您的错误在于,它需要在多一个空间[[$算-le 100]
Your mistake is that it need one more space in [[ $count -le 100]]
max=100
count=1
while [[ $count -le $max ]]
do
echo "$count"
((count++))
done
另一种解决方案:
Another solution :
while ((count < max+1)); do echo $((count++)); done
或
for ((i=count; i<max; i++)) { echo $i; }
或
for ((i=count; i<max; i++)); do echo $i; done
或
for i in {1..100}; do echo $i; done
这篇关于击而在DO循环语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文