Skip to content

Instantly share code, notes, and snippets.

@alexreg
Created July 25, 2013 03:50
Show Gist options
  • Save alexreg/6076788 to your computer and use it in GitHub Desktop.
Save alexreg/6076788 to your computer and use it in GitHub Desktop.
array_cmp() { local a="$1[i]" b="$2[i]" na nb i ; eval na=\${!$1[@]} nb=\${!$2[@]} ; for i in $na $nb ; do [[ "${!a}" = "${!b}" ]] || return $? ; done ; }
a=("foo")
b=("foo")
c=("foo", "bar")
array_cmp a b; echo $? $ should give 0!
array_cmp a a; echo $?
array_cmp b b; echo $?
array_cmp a c; echo $?
array_cmp b c; echo $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment