我有一个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 *** endI 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 endYou 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更多推荐
发布评论