UNIX KSH 脚本中是否有“Goto”?
KSH 中有没有办法退出 case 语句并转到某一行以便下次执行代码?或者有可以使用的 goto 标签吗?使用类似的东西而不是嵌套大量分支?
Is there a way within a KSH to exit a case statement and go to a certain line for next execution with the code? Or are there goto labels you can use? Anything like this used instead of nesting tons of branching?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
虽然发布问题的简化示例总是有帮助的(但这涵盖了您期望的所有意外情况),但考虑到您对 Mark Read 的评论回复,您可以将输入提示包装到 while 循环中,例如
另外,我同意 Mark, ksh 中没有标签或 goto。
我希望这有帮助。
While it always helps to post a simplified example of your problem (but that covers all contingencies you expect), given your comment reply to Mark Read, you can wrap the prompting for input into a while loop, like
Also, I agree with Mark, no labels or gotos in ksh.
I hope this helps.
没有标签或跳转。但是,您可以通过将数字传递给“break”内置函数来退出深度嵌套循环:break 2 退出两级,break 3 退出三级,等等。
There are no labels or goto. However, you can exit a deeply-nested loop by passing a number to the "break" builtin: break 2 to exit two levels, break 3 to exit three levels, etc.
有一个 bash goto 实现,如果你想使其适应 ksh (我到目前为止还没有)
There is a bash goto implementation, if you want to adapt it to ksh (I haven't so far)
我创建了名为 GOTO.ksh 的以下脚本:
在 ksh 脚本中,需要 goto(用于调试),我按如下方式调用它:
现在,如果确实想跳过 ksh 命令,只需输入:
如果脚本中,行将被注释掉,脚本将被写入 /tmp(前面带有“_”)并从那里执行。
I create the follwing script called GOTO.ksh:
In the ksh script were the goto's are needed (for debugging) I invoke this as follows:
Now if one does want to skip ksh commands just put in:
If there are #GOTO lines in the script, lines will be commented out, and the script will be written to /tmp (prepended with "_") and executed from there.