Pass javascript array to bash script through node child process

时间:2018-02-21 11:49:48

标签: javascript arrays bash child-process

I would like to pass a Javascript array to my bash script to loop over it.

What I am doing now is to call a child Process through node:

child = exec(directory + '\\downloadProducts.sh ' + promObj.requestURLS + ' ' + promObj.Name);

where promObj.requestURLS and promObj.Name are arrays.

My bash script looks as follows:

#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "params:"
echo "ID: $1"
echo "Name: $2"

declare -a IDArray=$1[@]
declare -a NameArray=$2[@]
echo "${NameArray[0]}"


for id in "${IDArray[@]}"; do
    for name in "${IDArray[@]}"; do
echo "I am " $id $name
  curl -u user:pass 
  "https://scihub.copernicus.eu/dhus/odata/v1/Products('"$id"')/\$value" --
   output $DIR/test/$name.zip
echo "download Product" $name
   done
done
echo "FINISHED ALL"

How can I pass the arrays properly? Thanks in advance

0 个答案:

没有答案