关于 KornShell 中的“for"循环 [英] Regarding 'for' loop in KornShell
本文介绍了关于 KornShell 中的“for"循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在 KornShell (ksh) 中使用for"来实现以下内容?这是 C 等效项:
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);
}
我想知道这是否可以仅使用for"而不是while"来实现
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.
推荐答案
不幸的是,它看起来好像 ksh
不支持基于范围的大括号扩展或支持 (( ))
构造以便紧凑地执行此操作,您需要像这样调用外部二进制 seq
:
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屋!
查看全文