Array as argument

hi

I've 2 bash script, in the first i define an array and I'd like to pass it as argument to the second script.
For example:
first_bash:

k=(1 2 3 4)
.......
#in the end i call the 2 script

./second_bash $k

then in the second_bash:

.....
echo "${1[*]}" #this not work

but i'm not able to manage the array in the 2 bash.

Any ideas?

thanks

D.

--------------------------------------------

Hi
I've tried as follow:

k=(1 2 3 4)
.......
#in the end i call the 2 script

./second_bash "${k[*]}"

and in the second_bash i call it as

....
passed_arr=$1
echo "${passed_arr[*]}"
....

and it seems like to work. Anyway I'll check in deep. Thanks
D.

No i'm wrong, it doesn't work.
In this way I'm passing one array as just one elemnt.
Still looking for a solution

Thanks

D.

In the second script you should do something like:

passed_arr=( $1 $2 $3 $4 )
$ls -l
total 12
-rwxr-x---    1 co01387r spweb          52 sep 28 13:19 sh1.sh
-rwxr-x---    1 co01387r spweb          65 sep 28 13:22 sh2.sh

$more sh1.sh 
k=("my" "vector" "other" "colum")

./sh2.sh ${k
[*]}

$more sh2.sh 
echo "Total camp:$#"
for camp in $*
do
        echo "Camp:${camp}"
done
$./sh1.sh 
Total camp:4
Camp:my
Camp:vector
Camp:other
Camp:colum

Thank you!
I got it

D.

passed_arr=( "$@" )

thx for reply :slight_smile:

That should be:

./sh2.sh "${k[@]}"