Shell 3 Array

Source: Internet
Author: User

Shell Array
shell支持一维数组(不支持多维数组),并且没有限定数组的大小。
Defining arrays
shell中,用括号来表示数组,数组元素用空格分隔,下标从0开始
Mode 1
 数组名=(值1 值2...值n),如array_name=(value0 value1 value2)
Mode 2
   array_name=(value0   value1   value2   )
Method 3 defines the value of the array individually
array_name[0]=value0array_name[1]=value1array_name[2]=value2
Reading an array
获取数组某个元素的值${数组名[下标]} 使用@可以获取数组中的所有元素${数组名[@]}
Gets the length of the array
获取数组长度的方法和获取字符串长度的方法相同。length=${#数组名[@]}length=${#数组名[*]}获取数组某元素的长度length=${#数组名[下标]}
#shell#!/bin/shlist1=("east" "west" "north" "south")list2=(‘one‘ ‘two‘  ‘three‘  ‘four‘)list3[0]="陆风"list3[1]="江铃"list3[3]="长安"echo "list1: "${list1[@]} ${#list1[@]}echo "list2: "${list2[@]} ${#list2[@]}echo "list3: "${list3[@]} ${#list3[@]}echo "list3[0]: "${list3[0]} ${#list3[0]}echo "list3[2]: "${list3[2]} ${#list3[2]}

List1:east West North South 4
List2:one three four 4
List3: Land Breeze Jiangling Chang ' an 3
List3[0]: Land Breeze 2
LIST3[2]: 0

Shell 3 Array

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.