如何在 csh shell 的命令提示符中使用 for 循环——寻找合适的衬里
来自 bash shell,我错过了一个简单的循环滚动(for i in (...); do ... done;)
您会在 cshell 中发布典型的单行循环吗?
请使用单行,而不是多行 谢谢
coming from bash shell, I missed on an easy rolling of loops (for i in (...); do ... done;)
Would you post typical one-liners of loops in cshell?
ONE LINERS PLEASE, and not multiple-lines
thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
csh
手册页指出:和
和
和
The
csh
man page states:and
and
and
哇,我已经很多年没有写过
csh
脚本了。但 Bill Joy 确实自己写了它,我想它值得一些怀旧的努力...或者只是
foreach i (*)
这个循环结构与 csh 具有的内置概念配合得很好 单词列表。这在 bash 中有点存在,但在普通的 posix shell 中不存在。
foreach
循环巧妙地迭代此数据结构。Wow, I haven't written a
csh
script in years. But Bill Joy did write it himself, I suppose it's worth some nostalgia effort...or just
foreach i (*)
This loop structure works well with a built-in concept that csh has of a word list. This is sort-of present in bash but not in vanilla posix shells.
The
foreach
loop neatly iterates through this data structure.我努力让 CSH shell 轻松循环并运行相同的命令。
正如这个答案所指出的: https://stackoverflow.com/a/1548355/1897481
让我放弃了一个制作一个单行作品。
最后决定使用以下别名来在循环中运行带有参数*的命令:
示例输出:
while 循环:
* 在循环中运行多个命令的示例:
在此示例中,三个命令
echo hi
、sleep 2s
和echo done waiting
正在循环中运行。I struggled to get CSH shell to easily loop over and run the same command over.
As pointed out by this answer: https://stackoverflow.com/a/1548355/1897481
Made me give up one making a oneliner work.
Finally settled to having the following aliases to run commands with arguments* in a loop:
Sample outputs:
The while loop:
* Example where multiple commands are run in a loop:
In this example, three commands
echo hi
,sleep 2s
andecho done waiting
are being run in the loop.我想说,尽管有 csh 选项,我已经以某种方式修复了它,所以你可以这样做:
I would say that i've fixed it somehow, despite csh options, so you can do something like this: