Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

BASH-Array array

Shulou Source: shulou.com Published: 2022-06-03 06:56:14 09月23日 Update

BASH-Array array

Array declaration: declare-an array actually does not need to declare, but assigns values to variables directly as an array. BASH will know that it is an array.

Array assignment:

You can also assign a value to the entire array: test= (var1 var2 var3... VarN)

Test= ([0] = var1 [1] = var2 [2] = var3... [n] = varN)

To assign values to an array, please refer to the definition of ordinary variables test [0] = var1.

Test [1] = var2

Test [2] = var3

Test [N] = varN-1

Array reference: ${test [subscript]}

For example:

$echo ${test [0]} var1

FYI. In addition, there are two special symbols, the * and @ signs, which refer to all array elements:

$echo ${test [*]} / * there are no spaces on both sides. This is indicated here because exblog recognizes errors.

Var1 var2 var3

# echo ${name [@]}

Var1 var2 var3

To display the number of elements in the entire array, use:

$echo ${# name [@]} 3

Referred Link:

Http://www.linuxfly.org/post/37/

Http://www.kklinux.com/html/biancheng/Shell/200905/02-5326.html

Tags: Array element variable normal special no two quantity way space symbol error reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL OPPO Reno Huawei Redmi Shulou Tech Info