csh 脚本 foreach 循环中的多个单词列表
我有一个 Cshell 脚本,我正在修改它以具有相关的输入和输出位置。 所有功能都发生在 foreach 循环中,如下所示:
set INPUT_LOCATION_LIST = "loc1 loc2 loc3 loc4"
foreach location ($INPUT_LOCATION_LIST)
#***Do some stuff ***
end
我希望有一个与输入列表具有不同值的输出列表,但在 foreach 循环的每次迭代中都遍历它。 foreach 的 man 只是
foreach name (wordlist)
定义了。所以只处理一个。我目前处理它的想法是让单词列表包含输入和输出位置,然后在脚本中解析它:
set INPUT_LOCATION_LIST = "loc1;out1 loc2;out2 loc3;out3 loc4;out4"
所以我想知道是否有人有更好的方法来做到这一点。
I have a Cshell script that I am modifying to have related input and output locations.
the functionality all happens in a foreach loop like so:
set INPUT_LOCATION_LIST = "loc1 loc2 loc3 loc4"
foreach location ($INPUT_LOCATION_LIST)
#***Do some stuff ***
end
I would like to have an output list with different values than the input list but traverse through it each iteration through the foreach loop. The man for foreach simply has
foreach name (wordlist)
as the definition. so only dealing with a single one. my current thought on dealing with it is have the wordlist contain both input and output location and then parse it out in the script:
set INPUT_LOCATION_LIST = "loc1;out1 loc2;out2 loc3;out3 loc4;out4"
so im wondering if anyone has a better way to do that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通常不使用 csh,但你的问题引起了我的注意。可能有一个步骤更少的解决方案,但这种事情在我的 csh 版本中有效:
基本思想是将分号分隔的字符串更改为空格分隔的字符串,然后将其解析为数组。
I don't normally use csh, but your question caught my eye. There's probably a solution with less steps, but this kind of thing worked in my version of csh:
Basic idea is just to change the semi-colon separated string into a space-separated string, then parse that into an array.
您可以使用
foreach
迭代一个列表,并通过将 at 视为数组并使用shift
迭代另一个列表:You can iterate through one list using
foreach
and through the other one by treating at like an array and usingshift
: