I want to symbolically link two arrays’ elements. For example, array1 = (AAA BBB CCC DDD), array2 = (001 002 003 004), 001->AAA, 002->BBB, 003->CCC and 004->DDD.
Here is the shell script I wrote, but it doesn’t work, and I couldn’t figure out where is wrong.
declare -a array1=(AAA BBB CCC DDD)
declare -a array2=(001 002 003 004)
num = ${#array1[@]}
ssh username@hostmachine 'for((i = 0 ; i < $num ; i++ )); do ln -sf ${array1[$i]} ${array2[$i]}; done'
Can anyone give me some hints/advice? Thank you in advance.
You should include all your bash code inside the parameter to
ssh, like this:because otherwise the ssh bash code won’t get access to your previously defined arrays, because they were defined in your computer not in the ssh one.