Multiple word lists in csh script foreach loop

I have a Cshell script that I modify to have associated input and output locations. functionality all happens in a foreach loop, for example:

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 go through it every iteration through the foreach loop. The man for foreach just has

foreach name (wordlist)

as a definition. therefore, it is only one thing. my current idea of ​​dealing with this is that the word list contains both input and output location and then parse it in a script:

set INPUT_LOCATION_LIST = "loc1;out1 loc2;out2 loc3;out3 loc4;out4"

so they are wondering if anyone has a better way to do this.

+3
source share
2 answers

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
+5

csh, . , , , csh :

foreach location ($INPUT_LOCATION_LIST)
    set one_word_with_space = ${location:s/;/ /}
    set loc_out = ($one_word_with_space)
    set loc = ${loc_out[1]}
    set out = ${loc_out[2]}
    ...
end

, , , .

+1

Source: https://habr.com/ru/post/1764750/


All Articles