Bash Arrays: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 24: Line 24:
==Reference==
==Reference==


Element arrays can be referenced with [...] notation:
Element arrays can be referenced with ${''var-name''[''index'']} notation:


  echo ${a[0]}
  echo ${a[0]}

Revision as of 21:23, 23 February 2018

Internal

Indexed Arrays

External

Overview

bash indexed arrays are 0-based and unidimensional. No explicit declaration is necessary if at least one element is initialized as described below:

Declaration

Initialization

Individual elements are initialized by using [...] notation:

a[0]="something"

Reference

Element arrays can be referenced with ${var-name[index]} notation:

echo ${a[0]}

Use Cases

Associative Arrays