传递数组从一个bash脚本到另一 [英] Passing An Array From One Bash Script to Another

查看:92
本文介绍了传递数组从一个bash脚本到另一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来编写shell脚本和时遇到一些困难。

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

我想实现

我在scriptOne.sh字符串数组,我想传递给scriptTwo.sh

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

我已经这样做了远东

我可以从第一个使用./scriptTwo.sh内执行第二个脚本,我已经通过使用字符串变量从一个到另一个 ./ scriptTwo.sh $ variableOne

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.

该问题是,当我试图通过一个数组变量它不会获得通过。我设法得到它通过使用数组的第一个条目 ./ scriptTwo.sh$ {数组[@]}然而,这仅仅是其中一个条目我需要所有的人。

The issues is 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.

在此先感谢您的帮助

推荐答案

您传递数组的方式是正确的。

Your way of passing the array is correct

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

问题可能是你如何得到它的方式。在 scriptTwo.sh ,用

array=("$@")

这篇关于传递数组从一个bash脚本到另一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆