for 循环范围不工作 ksh
尝试过这个
#!/bin/ksh
for i in {1..10}
do
echo "Welcome $i times"
done
我在 AIX 机器的 Ksh 中 。 我得到的输出为,
欢迎{1..10}次
这里出了什么问题? 不是应该打印从1到10吗? 编辑: 根据 perkolator 的帖子,来自 Iterate through a range of ints in ksh?
它仅有效在Linux上。 unix box ksh 有其他解决办法/替代品吗?
for i in 1 2 3 4 5 6 7 8 9 10
很丑。
谢谢。
I tried this,
#!/bin/ksh
for i in {1..10}
do
echo "Welcome $i times"
done
in Ksh of an AIX box.
I am getting the output as,
Welcome {1..10} times
What's wrong here?
Isn't it supposed to print from 1 to 10?.
Edit:
According to perkolator's post, from Iterating through a range of ints in 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
is ugly.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据我的记忆,AIX 上的标准
ksh
是一个较旧的变体。它可能不支持范围 for 循环。尝试使用ksh93
而不是ksh
运行它。它应该与ksh
位于同一位置,可能是/usr/bin
。否则,只需使用一些老式的东西,例如:
实际上,查看 publib 似乎证实了这一点(
ksh93
片段),所以我尝试沿着这条路线走下去。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 withksh93
instead ofksh
. This should be in the same place asksh
, probably/usr/bin
.Otherwise, just use something old-school like:
Actually, looking through publib seems to confirm this (the
ksh93
snippet) so I'd try to go down that route.原因是 93 之前的 ksh 实际上并不支持范围。
当您在 Linux 上运行它时,您会发现 ksh 实际上是 bash 或 ksh93 的链接。
尝试像这样循环:-
The reason being that pre-93 ksh doesn't actually support range.
When you run it on Linux you'll tend to find that ksh is actually a link to bash or ksh93.
Try looping like :-
您拥有的 ksh 版本似乎没有范围运算符。我在几个系统上都看到过这种情况。
你可以用 while 循环来解决这个问题:
在我的系统上,我通常使用 perl,所以脚本看起来像
It seems that the version of ksh you have does not have the range operator. I've seen this on several systems.
you can get around this with a while loop:
On my systems i typically use perl so the script would look like
您可以检查并查看 jot 是否有效 在此处查看手册页 或如果没有,请编写自己的小 C 程序来执行相同的操作并调用它。
jot 的语法类似于
You can check and see if jot works see man page here or if not, write your own little C program to do the same and call that.
The syntax for jot is something like