Array base for Linux arrays

Source: Internet
Author: User

The difference between the Linux array base "${a[*]} and $ A"

In bash, there are two ways to assign an array variable:

(1) name = (value1 ... valuen) the subscript starts at 0

(2) Name[index] = value

The following is a simple script stating the following:

#!/bin/bash# defining an array a=(a b c D E F) #把数组按字符串显示输出Echo${a[@]} #数组的长度表示 ${#A [*]}len=${#A [*]}Echo${#A [*]} #屏幕显示:6#改变数组元素的值A [3]='Vivian'Echo${a[*]} #屏幕显示: a b C Vivian E F # Loop output array element i=0 while[$i-LT $len] DoEcho${a[$i]}let i++ Done#循环输出数组元素的另一种写法, note that in the condition, the reference variable must use double quotation marks, otherwise the error for((j=0; j<"$len"; j=j+1 )) DoEcho${a[$j]} Done#循环输出数组元素的另一种写法, attention, ${a[.*]} cannot be written as $ A, $A default is the first element, if a ="a b c ded", you can write $ A forValueinch${a[*]} DoEcho$value DoneB="a b c d E F" forValueinch$B Do        Echo$value DoneArray=($B)EchoArray_length: ${#array [*]} #就相当于B=(1 2 3 4), don't believe you can try Echo ${array[@]}Echo${array[@]} #上面的例子还可以改写成以下内容: forValueinch${array[*]} DoEcho$value Done

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.