官术网_书友最值得收藏!

Creating an array and initializing it

You will now learn about creating an array in the Bash shell.

If the array name is FRUIT, then we can create an array, as follows:

FRUIT[index]=value

Index is the integer value. It should be 0 or any positive integer value.

We can also create an array, as follows:

$ declare -a array_name$ declare -a arrayname=(value1 value2 value3)

This is an example:

$ declare -a fruit=('Mango' 'Banana' 'Apple' 'Orange' 'Papaya')
$ declare -a array_name=(word1 word2 word3 ...)
$ declare -a fruit=( Pears Apple Mango Banana Papaya )
$ echo ${fruit[0]}
Pears
$ echo ${fruit[1]}
Apple
$ echo "All the fruits are ${fruit[*]}"
All the fruits are Pears Apple Mango Banana Papaya
$ echo "The number of elements in the array are ${#fruit[*]}"
The number of elements in the array are 5
$ unset fruit
or
$ unset ${fruit[*]}
主站蜘蛛池模板: 弥渡县| 吴旗县| 台南县| 临朐县| 通许县| 枣强县| 康马县| 利辛县| 合江县| 富裕县| 西畴县| 怀宁县| 治多县| 满城县| 衡阳县| 万荣县| 铜山县| 雷波县| 镶黄旗| 德州市| 乌恰县| 微山县| 尼木县| 赤城县| 南和县| 穆棱市| 崇明县| 客服| 和林格尔县| 辽阳市| 德令哈市| 峨边| 松桃| 安陆市| 来凤县| 赞皇县| 嘉义县| 社旗县| 开鲁县| 石渠县| 洛阳市|