- 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)代測控系統(tǒng)典型應(yīng)用實例
- Word 2003、Excel 2003、PowerPoint 2003上機指導與練習
- 網(wǎng)頁編程技術(shù)
- 條碼技術(shù)及應(yīng)用
- Windows XP中文版應(yīng)用基礎(chǔ)
- 機艙監(jiān)測與主機遙控
- VMware Performance and Capacity Management(Second Edition)
- SharePoint 2010開發(fā)最佳實踐
- Data Wrangling with Python
- 自動控制理論(非自動化專業(yè))
- 控制系統(tǒng)計算機仿真
- 西門子變頻器技術(shù)入門及實踐
- 空間站多臂機器人運動控制研究
- 單片機C語言應(yīng)用100例
- 機器人人工智能