csh脚本中的多个单词列表foreach循环(Multiple wordlists in csh script foreach loop)

编程入门 行业动态 更新时间:2024-10-20 21:04:34
csh脚本中的多个单词列表foreach循环(Multiple wordlists in csh script foreach loop)

我有一个Cshell脚本,我正在修改以具有相关的输入和输出位置。 功能都发生在foreach循环中,如下所示:

set INPUT_LOCATION_LIST = "loc1 loc2 loc3 loc4" foreach location ($INPUT_LOCATION_LIST) #***Do some stuff *** end

我希望有一个输出列表,其值不同于输入列表,但是每次迭代都会遍历foreach循环。 foreach的人只是

foreach name (wordlist)

作为定义。 所以只处理一个。 我目前处理它的想法是让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.

最满意答案

您可以使用foreach迭代一个列表,并通过像处理数组一样处理并使用shift来遍历另一个列表:

set INPUT_LOCATION_LIST = "loc1 loc2 loc3 loc4" set OUT_LIST = (out1 out2 out3 out4) foreach location ($INPUT_LOCATION_LIST) do_something $location $OUT_LIST[1] shift OUT_LIST end

You can iterate through one list using foreach and through the other one by treating at like an array and using shift:

set INPUT_LOCATION_LIST = "loc1 loc2 loc3 loc4" set OUT_LIST = (out1 out2 out3 out4) foreach location ($INPUT_LOCATION_LIST) do_something $location $OUT_LIST[1] shift OUT_LIST end

更多推荐

本文发布于:2023-07-16 13:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1128984.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   脚本   单词   列表   csh

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!