问题描述
我尝试过了
#!/bin/ksh
for i in {1..10}
do
echo "Welcome $i times"
done
AIX框的Ksh中的
.我得到的输出是,
in Ksh of an AIX box.I am getting the output as,
这是怎么了?它不是应该从1到10打印吗?根据perkolator的帖子,来自迭代ksh中的一系列int?
What's wrong here?Isn't it supposed to print from 1 to 10?.According to perkolator's post, from Iterating through a range of ints in ksh?
它仅在linux上有效. unix box ksh还有其他解决方法吗?
It works only on linux. Is there any other work around/replacements for unix box ksh?
for i in 1 2 3 4 5 6 7 8 9 10
很丑.
谢谢.
推荐答案
我从内存中认为AIX上的标准ksh
是较旧的变体.它可能不支持有范围的for循环.尝试使用ksh93
而不是ksh
运行它.该位置应与ksh
在同一位置,可能是/usr/bin
.
I think from memory that the standard ksh
on AIX is an older variant. It may not support the ranged for loop. Try to run it with ksh93
instead of ksh
. This should be in the same place as ksh
, probably /usr/bin
.
否则,只需使用一些老式的东西,如:
Otherwise, just use something old-school like:
i=1
while [[ $i -le 10 ]] ; do
echo "Welcome $i times"
i=$(expr $i + 1)
done
实际上,通过 publib 似乎证实了这一点(ksh93
代码段),因此我将尝试沿着这条路线走.
Actually, looking through publib seems to confirm this (the ksh93
snippet) so I'd try to go down that route.
这篇关于for循环范围不起作用ksh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!