声明数组但不定义数组(Shell脚本)

时间:2014-01-09 04:35:21

标签: arrays shell ubuntu

有很多guidesguides,其中显示了如何声明和定义数组

foo[0] = "abc" 
foo[1] = "def"

我想要实现的是声明一个数组但不定义它因为它不必立即定义,在大多数编程语言中它看起来像这样

int bar[100];

这可能是shell脚本语言吗?

1 个答案:

答案 0 :(得分:2)

你可以使用bash declare statement

来做到这一点
declare -a bar

然后您可以使用

添加值
bar[0]=1
bar[1]=2
bar[2]=3

使用

打印
echo ${bar[0]}
echo ${bar[1]}
echo ${bar[2]}

to output

1
2
3

您可以阅读更多here

相关问题