Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Created January 11, 2014 21:44
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save coderofsalvation/8377369 to your computer and use it in GitHub Desktop.
Save coderofsalvation/8377369 to your computer and use it in GitHub Desktop.
check if variable is array, returns 0 on success, 1 otherwise
# check if variable is array, returns 0 on success, 1 otherwise
# @param mixed
is_array()
{ #detect if arg is an array, returns 0 on sucess, 1 otherwise
[ -z "$1" ] && return 1
if [ -n "$BASH" ]; then
declare -p ${1} 2> /dev/null | grep 'declare \-a' >/dev/null && return 0
fi
return 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment