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

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[*]}
主站蜘蛛池模板: 山东| 阜阳市| 凌云县| 新津县| 平顶山市| 冀州市| 高青县| 治县。| 扎囊县| 怀安县| 新闻| 绥中县| 阿拉善盟| 普格县| 靖西县| 芷江| 岑溪市| 芦溪县| 高邑县| 神池县| 高尔夫| 蛟河市| 札达县| 滕州市| 星子县| 绥宁县| 雷山县| 大丰市| 开化县| 松江区| 北海市| 随州市| 循化| 榆社县| 龙门县| 曲水县| 驻马店市| 本溪市| 烟台市| 项城市| 武隆县|