I want to pass an array and an associative array between bash script.
I tried to send the argument as in the example bellow, but I get the erro message:
./b.sh: line 3: ${1[@]}: bad substitution
How can I do this?
Example:
First script a.sh that call other script b.sh
a.sh
#!/usr/bin/bash -x
declare -a array=("a" "b")
declare -A associative_array
associative_array[10]="Hello world"
./b.sh "${array[@]}" $associative_array
b.sh
#!/usr/bin/bash
declare -a array="${1[@]}"
declare -A associative_array="$2"
echo "${array[@]}"
echo "${associative_array[10]}"