title: Passing arguments with spaces via list in bash
body: <p>I am interesting in calling some function using dynamically generated arguments in a bash script.</p>
  
  <p>However, if some of the arguments had spaces, it does not seem to work.</p>
  
  <p>Let's have this test script:</p>
  
  <pre><code>#!/bin/bash
  # file uu.sh
  [[ -z $1 ]] || echo '$1' $1
  [[ -z $2 ]] || echo '$2' $2
  [[ -z $3 ]] || echo '$3' $3
  [[ -z $4 ]] || echo '$4' $4
  [[ -z $5 ]] || echo '$5' $5
  [[ -z $6 ]] || echo '$6' $6
  [[ -z $7 ]] || echo '$7' $7
  [[ -z $8 ]] || echo '$8' $8
  [[ -z $9 ]] || echo '$9' $9
  [[ -z $0 ]] || echo '$0' $0
  </code></pre>
  
  <p>Any my script:</p>
  
  <pre><code>#!/bin/bash
  # file vv.sh
  ARR=(-x)
  ARR+=($1)
  ARR+=("$1")
  ARR+=("'$1'")
  ARR+=("\"$1\"")
  bash uu.sh ${ARR[*]}
  echo
  bash uu.sh "${ARR[*]}"
  </code></pre>
  
  <p>When calling <code>bash vv.sh "a b"</code> I get the following result:</p>
  
  <pre><code>$2 -x
  $2 a
  $3 b
  $4 a
  $5 b
  $6 'a
  $7 b'
  $8 "a
  $9 b"
  $0 uu.sh
  
  $1 -x a b a b 'a b' "a b"
  $0 uu.sh
  </code></pre>
  
  <p>I am expecting a way to pass the variables to uu.sh such as the result would be:</p>
  
  <pre><code>$1 -x
  $2 a b
  $0 uu.sh
  </code></pre>
  
  <p>(Which I can get directly by calling <code>bash uu.sh -x a\ b</code>, or <code>bash uu.sh -x "a b"</code>, or <code>bash uu.sh -x 'a b'</code>)</p>