关于“为了” KornShell 中的循环
有没有办法在 KornShell (ksh) 中使用“for”来实现以下内容? 这是 C 的等价物:
for(i=1;i<20;i++)
{
printf("%d",i);
}
我想知道是否可以仅使用“for”而不是“while”来实现,
我尝试了以下方法,但它似乎不起作用。
for i in [1-20]
do
print $i
done
请让我知道您的想法和解决方案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这并不是一个真正的答案,而是给临时 ksh 用户的一个参考。
编辑于 2019 年 5 月 12 日(下面粗体进行了少量修改,其他信息现已
受攻击)。为了澄清这里的一些评论,典型供应商安装中有 2 个 ksh 可用(非 Linux(也许也是?))。
Solaris 和 AIX 有 ksh 和 ksh93(对于其他供应商来说可能也是如此)。基本 ksh 也称为 ksh88。 ,1995 中描述了 Ksh93
新的 Kornshell 命令和编程语言 真正的ksh(不是pdksh),主要使用名为ksh的ksh93。
最后,为了进一步混淆事情,不要让 1995 年的发布日期欺骗了您,ksh
继续正在由 AT&T 的 David Korn 和 Glen Fowler 积极开发,直到2012年? 版本每年发布 2-3 次。某些 Linux 版本会选择较新的版本。这些较新的版本具有非常先进的功能
(大部分内容取自
AT&T 研究 UWIN 页面。搜索链接 '注释和更改'(死链接))(请注意,上面的...,通常表示删除了一些限定信息)
Korn 和 Fowler 还为使用 Mingw 或 Cygwin 等系统的用户制作了一个高级环境 UWIN(Unix for Windows),这值得单独写一篇文章。 UWIN 的缺点是,它
AT&T Common Public License V 1.0Eclipse 公共许可证* 不是 GNU。请参阅
UWin主页(死链接) :不幸的是已经过时了,最好在上面的 dnld 链接中查找。嗯,这好多了Glenn Fowler 的 UWin 常见问题解答< /a>(也死了,时间机器有人吗?)。我希望这有帮助!
编辑于2019年5月12日。死链接的原因是什么?
大卫Korn 和 Glen Fowler 被解雇(AT&T,2012 年?
后来有消息称他们在 Google 工作。我无法证实这一点,所以将其视为旧谣言。
并参见 Ksh93 死了吗?
ast git-hub 站点 。
ast
是包含ksh93
的总体包。您可以在那里获取新的源代码并编译它。这是项目描述的文本(
README.md
中有更多信息)。*
EPL 取代了 AT&T 原来的 CPL。
Not really an answer, but an FYI to casual ksh users.
Edit 2019-05-12 (Minor edits below in bold, other info is now
stricken).To clarify on several comments here, there are 2 ksh's available in typical vendor installations (non-Linux (maybe them too?)).
Solaris and AIX have a ksh and ksh93 (probably true for other vendors too). The base ksh is also known as ksh88. Ksh93 is described in The New Kornshell Command and Programming Language, 1995
Linux systems that have a true ksh (not pdksh), mostly use ksh93 named as ksh.
Finally, to further confuse things, don't let the 1995 pub date trick you, ksh
continues underwas under active development by David Korn and Glen Fowler at AT&T until 2012?. Versions were released 2-3X per year. Some Linux versions pick up the newer versions.These newer versions have very advanced features
(most of this taken from
AT&T research UWIN page. search for the link 'notes and changes'(dead link) )(note that ...s in above, usually indicate some qualifying information removed)
Korn and Fowler had also produced an advanced environment, UWIN (Unix for Windows) for people that use systems like Mingw or Cygwin, that would be worthy of a separate post. The downside for UWIN is,
AT&T Common Public License V 1.0Eclipse Public License* is not GNU.See
UWin main page(dead link) : unfortunately out of date, better to nose around in the dnld link above. Hmm, this is much betterGlenn Fowler's FAQ for UWin(also dead, Time Machine anyone?).I hope this helps!
Edit 2019-05-12 . The reason for the dead links?
David Korn and Glen Fowler Laid Off (at AT&T, 2012?
Information later surfaced that they are working at Google. I can't confirm this, so consider it as an old rumor.
AND see Is Ksh93 dead?
There still seems to be some activity at the ast git-hub site .
ast
is the over-arching package that includesksh93
. You can get the fresh source code there and compile it.Here is the text of the project description. (There is considerably more information in the
README.md
).*
The EPL replaced AT&T's original CPL.
ksh93 支持类似 C 的
(( ...;...; ...))
:这将产生:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
哎呀,即使是旧的语法(使用 '{' ... '}' 而不是 'do ... done' 也可以工作):
在旧的 shell 中,您仍然可以获得相同的效果
ksh93 supports the C-like
(( ...;...; ...))
:This will produce:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Heck, even the old syntax (using '{' ... '}' instead of 'do ... done' will work):
In older shells, you can still get the same effect with
不幸的是,看起来
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 binaryseq
like so:如果“braceexpand”为“on”,ksh93 也提供大括号扩展。检查“set -o”,然后使用花括号 {}
ksh93 offers braceexpansion also if "braceexpand" is "on". Check with "set -o" and then use curly braces {}