Show Menu

bash array reference Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Create / delete array

declare -a ARRAYNAME
-a for array
declare -A DICTNAME
-A for dict
ARRAY=­(value1 value2 ... valueN)
DICT=( [mark]=79 [john]=93 [ella]=87 [mila]=83 )
directly set. no other value display
read -a ARRAY
read from user input
unset ARRAY[1]
delete only 1 element
unset ARRAY
delete whole array
ARRAY=( $(ls) )
put ls output into array

get value

index array of element
key array of elements
get all elements, split by IFS
get all elements, split by space
get third element
get length of ARRAY[­sub­script]
get length of ARRAY
Retrieve n elements starting at index s