关于KornShell中的'for'循环 [英] Regarding 'for' loop in KornShell
本文介绍了关于KornShell中的'for'循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是C等价物:
$ b $ pre $
for(i = 1; i <20; i ++)
{
printf(%d,i);
$ b我想知道是否可以使用'for'而不是'而'
我尝试了以下,似乎并不奏效。
<$ c我在[1-20]
做
print $ i
完成
请让我知道您的想法和解决方案。
解决方案
如果 ksh
不支持基于范围的大括号扩展,或者支持(())
构造,紧凑的,你需要像这样调用外部的二进制 seq
:
for i in $(seq 1 20);做
echo $ i
完成
Is there a way to implement the following using 'for' in KornShell (ksh)? Here is the C equivalent:
for(i=1;i<20;i++)
{
printf("%d",i);
}
I was wondering if this can be implemented using just 'for' and not 'while'
I tried the following, it does not seem to work.
for i in [1-20]
do
print $i
done
Please let me know your ideas and solutions.
解决方案
Unfortunately, it looks as if ksh
does not have support for range-based brace expansion or support the (( ))
construct so to do this compactly, you'll need to call the external binary seq
like so:
for i in $(seq 1 20); do
echo $i
done
这篇关于关于KornShell中的'for'循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文