Passing An Array From One Bash Script to Another

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 19:59:44

问题


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


回答1:


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=("$@")


来源:https://stackoverflow.com/questions/16019389/passing-an-array-from-one-bash-script-to-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!