Find the answer to your Linux question:
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[@]})'" ...
  1. #1
    Just 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:
    Code:
    ssh $USER@$SERVER command "'$(echo ${array[@]})'"
    I get it back on my server in the forms of string but i cant convert it back to array.
    On the remote server i m using korn shell.
    On my machine bash.

    Thank you for helping.

  2. #2
    Linux 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?

  3. #3
    Just 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.

  4. #4
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Code:
    $ var="1 2 3 4"
    $ array=($var)
    $ echo ${array[1]}
    2

  5. #5
    Just Joined!
    Join Date
    Dec 2008
    Posts
    4
    On the client side my in my script i have,
    Code:
    num="1 2 3 4"
    ssh $USER@$SERVER remote_script "'$(echo ${num[@]})'"
    On the server side i have:
    Code:
    num="$1"
    for i in "${num[0]}"
      echo "num $i"
    done
    and it prints "num 1 2 3 4" instead of :
    num 1
    num 2
    num 3
    num 4

  6. #6
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Code:
    $ var="1 2 3 4"
    $ array=($var)
    $ echo ${array[1]}
    2

  7. #7
    Just Joined!
    Join Date
    Dec 2008
    Posts
    4
    I tried it already like this on server script :
    Code:
    num=($1)
    for i in "${num[@]}"
    do
      echo "num $i"
    done
    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 says
    Code:
    syntax error: '(' unexpected

  8. #8
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Works for my korn shell.

  9. #9
    drl
    drl is offline
    Linux Engineer drl's Avatar
    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:
    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
    Producing:
    Code:
    $ ./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 : `(' unexpected
    The first seems to be allowed in earlier ksh versions and even in pdksh ... cheers, drl
    Welcome - 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 )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...