Please Correct this Array Script

Here is the script. I am not able to increment and Print echo "2=" ${arr[2]}
(Bold line)
Can someone please help me correct it? I am thinking there is some escape sequence error. Just started learning scripts ...

Thanks

#!/bin/ksh

set -A arr a1 a2 a3 a4

# START

Server1=gmi

Username=test

let j=2

echo "above ssh=" ${arr[j]}

ssh -xq $Server1 -l $Username /usr/bin/ksh <<-EOS

let j=0

out=\\$\{arr[j]\}

echo "0out="\\$out

for loop in ${arr[*]}

do

let j=j+1

echo "d=" \$j

echo "1=" \$loop

echo "2=" ${arr[2]}

done

EOS

# END

i use bash these days. maybe this example will help it will print like:
hope that helps.

Anzahl= 6
1 2
2 3
3 4
4 5
5 6
6 7

#!/bin/bash

liste=( 1 2 3 4 5 6)

echo "Anzahl=" ${#liste[*]}

for ((i=0;i<${#liste[*]} ; i++ ))
do
echo -n ${liste[ $i ]} " "
echo $(( ++liste[ $i ] ))
done

Where have I seen this before?

Grumpf - Thanks for the help. Let me try it. Not sure if I need to to print it the same way as you suggested. I still think there is a simple escape sequence which i am missing. Anways I will try you example.

Shock - Was that question to me? If it was for me I am sure you would have not see it earlier .. coz Its just a part of the script in my present environment.

Thanks guys

Looks an awful lot like this:

Homework assignment, impatient poster, or two people working on the same problem?

Hmmm... Looks like 2 people working on the same problem .. My collogue passed it on to me .... Now i see where he got the problem from :slight_smile:

Thanks anyways!!

You'll also see that I gave an answer in the other thread - for some reason he didn't seem to like it, but I think it should work once he defines the array on the remote system (as opposed to locally). That is, unless he has some other requirement that has not been made clear.