Function: pop

Remove top element (array[0]) from stack and place in varname

USAGE: pop arrayname varname:var

  local arrayname=${1:?Array name required} array val varname=${2:-var}

Copy the array, $arrayname, to local array

  eval "array=( \"\${$arrayname[@]}\" )"

Check that there is at least one element in the array

  if [ ${#array[@]} -lt 1 ]
    eval "$varname="
    return 1

Store first element of array in $varname

  eval "$varname=\${array[0]}"

Remove first element

  unset array[0]

Rebuild array

  eval "$arrayname=( \"\${array[@]}\" )"