in reply to Environment variable is an array
Like Anon says above, shell arrays are a concept internal to the shell, they can't be exported.
Here are some things you could do if you still want to pass an array of string. The easiest way might be to pass the values of the array as command-line arguments and access them as @ARGV.
You could also write the values to a file (either a regular file or pipe) separated by nuls, and read that file from perl, eg.perl -we 'print "<<<$_>>>\n" for @ARGV;' -- "${NUMS[@]}"
printf "%s\0" "${NUMS[@]}" | perl -we 'my @NUMS; { local $/ = "\0"; ch +omp(@NUMS = <STDIN>); }; warn "<<<$_>>>\n" for @NUMS; '
You needn't use the standard input, you can pass the name or filedescriptor of the file to the script in the command line or environment.
You could also avoid files and stuff the values in separate environment variables, but that gets ugly, so I recommend files instead.
for k in "${!NUMS[@]}"; do export NUMS_$k=${NUMS[k]}; done; perl -we 'my @NUMS; while (my($k, $v) = each %ENV) { $k =~ /\ANUMS_(.+ +)\z/ and $NUMS[$1] = $v; } print "<<<$_>>>\n" for @NUMS;'
|
|---|