How do I pass an array as a variable from a first bash shell script to a second script.
first.sh#!/bin/bash
AR=('foo' 'bar' 'baz' 'bat')
sh second.sh "$AR" # foo
sh second.sh "${AR[@]}" # foo
second.sh
#!/bin/bash
ARR=$1
echo ${ARR[@]}
In both cases, the result is foo
. But the result I want is foo bar baz bat
.
What am I doing wrong and how do I fix it?