Results 1 to 9 of 9
Hello all,
I m having difficulties now to get my array back on script on remote server.
I' m passing the array like this:
Code:
ssh $USER@$SERVER command "'$(echo ${array[@]})'"
...
- 12-18-2008 #1Just Joined!
- Join Date
- Dec 2008
- Posts
- 4
passing array to script via ssh
Hello all,
I m having difficulties now to get my array back on script on remote server.
I' m passing the array like this:
I get it back on my server in the forms of string but i cant convert it back to array.Code:ssh $USER@$SERVER command "'$(echo ${array[@]})'"
On the remote server i m using korn shell.
On my machine bash.
Thank you for helping.
- 12-18-2008 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
So "command" is a ksh script? In that case, the arguments are already positional parameters. Isn't that enough?
- 12-18-2008 #3Just Joined!
- Join Date
- Dec 2008
- Posts
- 4
And how would loop through it ?
I tried different ways but it always print just all my array element as just one string.
In my loop there is just one loop that prints a single string with all my array element.
- 12-19-2008 #4Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Code:$ var="1 2 3 4" $ array=($var) $ echo ${array[1]} 2
- 12-19-2008 #5Just Joined!
- Join Date
- Dec 2008
- Posts
- 4
On the client side my in my script i have,
On the server side i have:Code:num="1 2 3 4" ssh $USER@$SERVER remote_script "'$(echo ${num[@]})'"
and it prints "num 1 2 3 4" instead of :Code:num="$1" for i in "${num[0]}" echo "num $i" done
num 1
num 2
num 3
num 4
- 12-19-2008 #6Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Code:$ var="1 2 3 4" $ array=($var) $ echo ${array[1]} 2
- 12-19-2008 #7Just Joined!
- Join Date
- Dec 2008
- Posts
- 4
I tried it already like this on server script :
but as i said in my first post, im using korn shell on the server, and it seems that this syntax is not working with this shell as it saysCode:num=($1) for i in "${num[@]}" do echo "num $i" done
Code:syntax error: '(' unexpected
- 12-19-2008 #8Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Works for my korn shell.
- 12-19-2008 #9Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Newer versions have bash-like array setting syntax:
Producing:Code:#!/usr/bin/env ksh # @(#) s1 Demonstrate ksh array setting syntax. echo export LC_ALL=C echo "Environment: LC_ALL = $LC_ALL" echo "(Versions displayed with local utility \"version\")" version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) echo echo " With earlier syntax:" set -A b goodbye moon print ${b[*]} echo echo " With 93s+ syntax:" a=( hello world ) print ${a[*]} exit 0
The first seems to be allowed in earlier ksh versions and even in pdksh ... cheers, drlCode:$ ./s1 Environment: LC_ALL = C (Versions displayed with local utility "version") SunOS 5.10 ksh M-11/16/88i With earlier syntax: goodbye moon With 93s+ syntax: ./s1[18]: syntax error at line 18 : `(' unexpectedWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote