shell数组

Catalogue
  1. 1. 删除数组中的元素

删除数组中的元素

1
2
3
4
5
6
7
$ array=( "one two" "three four" "five six" )
$ unset array[1]
$ array=( "${array[@]}" )
$ echo ${array[0]}
one two
$ echo ${array[1]}
five six

Shell 数组并不是真正用作可以从中添加和删除项目的数据结构(它们主要用于为以下情况提供第二级引用:提供somecommand有两个,而不是四个参数)。但这应该适用于大多数情况。

1
2
arr=( "one two" "three four" )
somecommand "${arr[@]}"