avatar
shell script for "for" loop# Unix - 噫吁兮,危乎高哉
b*l
1
In this script:
for i in 1 2 3 4; do echo $i; done
It will print 1 2 3 4. But if I want to loop from 1 to N which is very large,
e.g, 100000, how to do that in bash or ksh using "for" loop? Is there anything
like "for i in 1:10000"? This one does not work.
3x
avatar
f*h
2
you can increase i by i=`expr $i + 1`

【在 b***l 的大作中提到】
: In this script:
: for i in 1 2 3 4; do echo $i; done
: It will print 1 2 3 4. But if I want to loop from 1 to N which is very large,
: e.g, 100000, how to do that in bash or ksh using "for" loop? Is there anything
: like "for i in 1:10000"? This one does not work.
: 3x

avatar
b*l
3
I used this approach in a while loop to do the same thing. But I am wondering
if there is a short cut other than this way.
Thanks any way.

large,
anything

【在 f********h 的大作中提到】
: you can increase i by i=`expr $i + 1`
avatar
c*t
4
nope. That was the standard approach :)

【在 b***l 的大作中提到】
: I used this approach in a while loop to do the same thing. But I am wondering
: if there is a short cut other than this way.
: Thanks any way.
:
: large,
: anything

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。