title: Content of array in bash is OK when called directly, but lost when called from function
body: <p>I am trying to use xmllint to search an xml file and store the values I need into an array. Here is what I am doing:</p>
  
  <pre><code>#!/bin/sh
  
  function getProfilePaths {
      unset profilePaths
      unset profilePathsArr
      profilePaths=$(echo 'cat //profiles/profile/@path' | xmllint --shell file.xml | grep '=' | grep -v "&gt;" | cut -f 2 -d "=" | tr -d \")
      profilePathsArr+=( $(echo $profilePaths))
      return 0
  }
  </code></pre>
  
  <p>In another function I have:</p>
  
  <pre><code>function useProfilePaths {
      getProfilePaths
      for i in ${profilePathsArr[@]}; do
      echo $i
      done
      return 0
  }
  
  useProfilePaths
  </code></pre>
  
  <p>The behavior of the function changes whether I do the commands manually on the command line VS calling them from different function as part of a wrapper script. When I can my function from a wrapper script, the items in the array are 1, compared to when I do it from the command line, it's 2:</p>
  
  <pre><code>$ echo ${#profilePathsArr[@]}
  2
  </code></pre>
  
  <p>The content of profilePaths looks like this when echoed:</p>
  
  <pre><code>$ echo ${profilePaths}
  /Profile/Path/1 /Profile/Path/2
  </code></pre>
  
  <p>I am not sure what the separator is for an xmllint call.</p>
  
  <p>When I call my function from my wrapper script, the content of the first iteration of the for loop looks like this:</p>
  
  <pre><code>for i in ${profilePathsArr[@]}; do
      echo $i
  done
  </code></pre>
  
  <p>the first echo looks like:</p>
  
  <pre><code>/Profile/Path/1
  /Profile/Path/2
  </code></pre>
  
  <p>... and the second echo is empty.</p>
  
  <p>Can anyone help me debug this issue? If I could find out what is the separator used by xmllint, maybe I could parse the items correctly in the array.</p>
  
  <p>FYI, I have already tried the following approach, with the same result:</p>
  
  <pre><code>profilePaths=($(echo 'cat //profiles/profile/@path' | xmllint --shell file.xml | grep '=' | grep -v "&gt;" | cut -f 2 -d "=" | tr -d \"))
  </code></pre>