Function: pop_end

Remove element from end of list and store in varname

USAGE: pop_end arrayname varname:var

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

Copy the array, $arrayname, to local array

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

Check that there is at least one element in the array

#  [ $n -lt 1 ] && return 1
  (( $n )) || return 1

Store last element in $varname

  printf -v "$varname" "${array[n-1]}"
  unset array[n-1]

Copy array back to $arrayname

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