Bash Arrays: Difference between revisions
Jump to navigation
Jump to search
Line 28: | Line 28: | ||
echo ${a[0]} | echo ${a[0]} | ||
If the specific element was not initialized, or the array variable does not exist, the reference attempt will return the blank string. | If the array variable [[Bash_Variables#Undeclared_Variable|was not previously declared]], or if the specific element [[Bash_Variables#Uninitialized_Variable|was not initialized]], or the array variable does not exist, the reference attempt will return the blank string. | ||
==Use Cases== | ==Use Cases== | ||
=Associative Arrays= | =Associative Arrays= |
Revision as of 21:35, 23 February 2018
Internal
Indexed Arrays
External
- http://www.gnu.org/software/bash/manual/html_node/Arrays.html#Arrays
- http://tldp.org/LDP/abs/html/arrays.html
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 ${var-name[index]}=value notation:
a[0]="something"
Reference
Element arrays can be referenced with ${var-name[index]} notation:
echo ${a[0]}
If the array variable was not previously declared, or if the specific element was not initialized, or the array variable does not exist, the reference attempt will return the blank string.