Skip to content

Instantly share code, notes, and snippets.

@aleofreddi
Created March 19, 2020 12:24
Show Gist options
  • Save aleofreddi/e26609dde53c2d0198130bccfcc073b3 to your computer and use it in GitHub Desktop.
Save aleofreddi/e26609dde53c2d0198130bccfcc073b3 to your computer and use it in GitHub Desktop.
# Bash array cheatsheet
Declare declare -a array=('a' 'b' 'c')
Length ${#array[@]}
Indices ${!array[@]}
Push n (append) array+=('i_0' ... 'i_n')
Pop n (bash>=4) unset 'array[-n]'
Pop n (bash<4) unset 'arr[${#arr[@]}-n]'
Shift n array=("${array[@]:n}")
Unshift n array=("i_0" ... "i_n" "${array[@]:n}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment