Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing An Array From One Bash Script to Another

I am new to writing Shell Scripts and am having some difficulties.

What I Want To Achieve

I have an array of strings in scriptOne.sh that I want to pass to scriptTwo.sh

What I Have Done So Far

I can execute the second script from inside the first using ./scriptTwo.sh and I have passed string variables from one to the other using ./scriptTwo.sh $variableOne.

The issues are when I try to pass an array variable it doesn't get passed. I have managed to get it to pass the first entry of the array using ./scriptTwo.sh "${array[@]}" however this is only one of the entries and I need all of them.

Thanks in advance for your help

like image 229
StuStirling Avatar asked Apr 15 '13 15:04

StuStirling


1 Answers

Your way of passing the array is correct

./scriptTwo.sh "${array[@]}"

The problem is probably in the way how you receive it. In scriptTwo.sh, use

array=("$@")
like image 105
choroba Avatar answered Oct 12 '22 13:10

choroba