Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Last active February 21, 2019 22:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ormaaj/3e88968592e2d5b8f39f to your computer and use it in GitHub Desktop.
Save ormaaj/3e88968592e2d5b8f39f to your computer and use it in GitHub Desktop.
Non-serious bash 2d array implementation
#!/usr/bin/env bash
function getElem {
while
${!1+\:} return 1
typeset -a "__getElemArr=${!1}"
set -- "__getElemArr${1#*]}"
[[ $1 == *\[!(@]|\*]) ]]
do :
done
printf '<%s> ' "${!1}"
echo
}
#a=$'( \'(a b c)\' $\'([3]=\\\'(d e f)\\\' [5]=1 2 3)\' \'(g h i)\' )'
a=( '(a b c)' $'([3]=\'(d e f)\' [5]=1 2 3)' '(g h i)' )
# typeset -a a=(([0]=a [1]=b [2]=c) ([3]=([0]=d [1]=e [2]=f) [5]=1 [6]=2 [7]=3) ([0]=g [1]=h [2]=i) )
getElem 'a[1][3][@]' || echo unset
# vim: set fenc=utf-8 ff=unix ft=sh :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment