Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Created January 11, 2014 21:44
Show Gist options
  • Select an option

  • Save coderofsalvation/8377369 to your computer and use it in GitHub Desktop.

Select an option

Save coderofsalvation/8377369 to your computer and use it in GitHub Desktop.

Revisions

  1. coderofsalvation created this gist Jan 11, 2014.
    11 changes: 11 additions & 0 deletions is_array.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # 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
    }