Passing an array from one Bash Script to another

I am new to shell scripting and have some difficulties.

What i want to achieve

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

What have i done so far

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

The problem is that when I try to pass an array variable, it is not passed. I managed to get it to pass the first record of the array using ./scriptTwo.sh "${array[@]}" however this is only one of the records and I need all of them.

Thank you in advance

+7
source share
1 answer

Your array transfer method is correct

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

The problem is probably how you get it. In scriptTwo.sh use

 array=(" $@ ") 
+7
source

All Articles