set -A arr a1 a2 a3 a4
# START
ssh -xq $Server1 -l $Username /usr/bin/ksh <<-EOS
integer j=0
for loop in ${arr[*]}
do
printf "array - ${arr[$j]}\n"
(( j = j + 1 ))
j=`expr j+1`
done
EOS
# END
=========
this is not giving me correct output.
I just want to print a1 a2 a3 a4 a5 as per my variable j inside ssh
pls do let me know any solution using a variable
without a variable directly using a loop for array works fine in ssh and using a variable works fine without ssh but giving problem with ssh
i guess ineed to escape few chars which i am nt sure.
I'll appriciate if you can post any working dummy code
i tried all solution but nothng worked for me.
It's late for me, but at a glance, and without testing it myself, I'd say that you're declaring the "arr" array locally, then trying to gather the elements of it remotely.
Does this work?
# START
ssh -xq $Server1 -l $Username /usr/bin/ksh <<-EOS
set -A arr a1 a2 a3 a4
integer j=0
for loop in ${arr[*]}
do
printf "array - ${arr[$j]}\n"
(( j = j + 1 ))
j=`expr j+1`
done
EOS
# END
Um, yes, that you are using the variable means that you are, in fact, using the variable. That's what 'using' means. As macosta pointed out, variables don't carry across like that. if you don't declare and populate the array in the block for the ssh then it won't know what it is.