如下:
语法 | 英文解释 | 中文解释 |
arr=() | Create an empty array | 创建一个空的数组 |
arr=(1 2 3) | Initialize array | 初始化数组 |
${arr[2]} | Retrieve third element | 取得第三个元素 |
${arr[@]} | Retrieve all elements | 取得所有元素 |
${!arr[@]} | Retrieve array indices | 取得数组索引 |
${#arr[@]} | Calculate array size | 得到数组的大小(其中共有多少个元素) |
arr[0]=3 | Overwrite 1st element | 覆盖第一个元素 |
arr+=(4) | Append value(s) | 数组末尾追加元素 |
str=$(ls) | Save ls output as a string | 将ls命令的输出保存为一个字符串 |
arr=( $(ls) ) | Save ls output as an array of files | 将ls命令的输出保存为一个文件名的数组 |
${arr[@]:s:n} | Retrieve n elements starting at index s | 从第s-1个开始,取得一共n个元素 |
参考资料
==============
You don‘t know Bash: An introduction to Bash arrays
https://opensource.com/article/18/5/you-dont-know-bash-intro-bash-arrays
Shell中的特殊符号和含义简明总结
https://blog.csdn.net/wejfoasdbsdg/article/details/53289589
https://www.cnblogs.com/xuxm2007/archive/2011/10/20/2218846.html
原文:https://www.cnblogs.com/awpatp/p/14136552.html