title: How to slice an array in Bash
body: <p>Looking the "Array" section in the bash(1) man page, I didn't find a way to slice an array.</p>
  
  <p>So I came up with this overly complicated function:</p>
  
  <pre><code>#!/bin/bash
  
  # @brief: slice a bash array
  # @arg1:  output-name
  # @arg2:  input-name
  # @args:  seq args
  # ----------------------------------------------
  function slice() {
     local output=$1
     local input=$2
     shift 2
     local indexes=$(seq $*)
  
     local -i i
     local tmp=$(for i in $indexes 
                   do echo "$(eval echo \"\${$input[$i]}\")" 
                 done)
  
     local IFS=$'\n'
     eval $output="( \$tmp )"
  }
  </code></pre>
  
  <p>Used like this:</p>
  
  <pre><code>$ A=( foo bar "a  b c" 42 )
  $ slice B A 1 2
  $ echo "${B[0]}"  # bar
  $ echo "${B[1]}"  # a  b c
  </code></pre>
  
  <p>Is there a better way to do this?</p>