shell数组
来源:互联网 发布:知乎lookfantastic 编辑:程序博客网 时间:2024/06/08 06:58
可以同直接赋值的方式初始化数组
tao@tao-ThinkCentre-M8600t-N000:~$ array=(1 2 3 4)
tao@tao-ThinkCentre-M8600t-N000:~$ echo $array
1
可见$array 代表数值第一个元素
打印数组下表为2的元素,数组是从0开始的
tao@tao-ThinkCentre-M8600t-N000:~$ echo ${array[2]}
3
计算数组的长度
tao@tao-ThinkCentre-M8600t-N000:~$ echo ${#array[@]}
4
打印数组中的所有元素,哈哈哈,这里不需要循环
tao@tao-ThinkCentre-M8600t-N000:~$ echo ${array[*]}
1 2 3 4
改变数组中的某一个下标的值
tao@tao-ThinkCentre-M8600t-N000:~$ array[1]=9
tao@tao-ThinkCentre-M8600t-N000:~$ echo ${array[*]}
1 9 3 4
删除整个数组
tao@tao-ThinkCentre-M8600t-N000:~$ unset array
tao@tao-ThinkCentre-M8600t-N000:~$ echo ${array[*]}
删除数组中的某一个元素
tao@tao-ThinkCentre-M8600t-N000:~$ unset array[1]
tao@tao-ThinkCentre-M8600t-N000:~$ echo ${array[*]}
1 3 4
数组中的分片
tao@tao-ThinkCentre-M8600t-N000:~$ echo ${array[@]:0:2}
1 3
数组中的替换:这里的替换是指数组中的元素而不是指下标
tao@tao-ThinkCentre-M8600t-N000:~$ echo ${array[@]/3/10}
1 10 4
- shell数组
- shell数组
- shell 数组
- shell数组
- shell数组
- shell 数组
- shell-------------数组
- shell 数组
- shell数组
- shell数组
- shell数组
- Shell 数组
- shell数组
- shell数组
- shell 数组
- shell数组
- shell数组
- shell 数组
- 去除jQuery mobile默认样式
- 常见的github错误和处理
- 懂商业的技术合伙人(15):微信小程序
- python 的 subprocess模块用法 popen
- 【C#】往按钮事件中传递自定义参数
- shell数组
- 一次电商系统的微服务架构改造(一)
- Eclipse 反编译插件JadClipse安装
- ES6学习之路(五) 函数的扩展
- IoT物联网云平台比较
- 【Java】Java中判断进行数据库批量操作是否成功
- Filter(过滤器)与Interceptor(拦截器)的区别
- Ubuntu 环境下调试修改OpenCV3.2.0源码
- Gitlab v8.17.4 安装并汉化(ubuntu14.04)