- Learning Linux Shell Scripting
- Ganesh Naik
- 144字
- 2021-06-25 22:02:57
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[*]}
推薦閱讀
- 現(xiàn)代測控電子技術(shù)
- 教父母學(xué)會上網(wǎng)
- 自動檢測與轉(zhuǎn)換技術(shù)
- B2B2C網(wǎng)上商城開發(fā)指南
- 自動生產(chǎn)線的拆裝與調(diào)試
- 人工智能實踐錄
- 人工智能趣味入門:光環(huán)板程序設(shè)計
- 單片機C語言應(yīng)用100例
- 貫通Java Web開發(fā)三劍客
- 網(wǎng)絡(luò)管理工具實用詳解
- 嵌入式GUI開發(fā)設(shè)計
- 工業(yè)機器人力覺視覺控制高級應(yīng)用
- 貫通開源Web圖形與報表技術(shù)全集
- 手把手教你學(xué)Photoshop CS3
- 系統(tǒng)安裝、維護(hù)與數(shù)據(jù)備份技巧