title: BASH is automatically adding single quotes to string variables
body: <p><a href="https://stackoverflow.com/questions/32150672/bash-automatically-adding-quotes-to-strin">This problem is almost similar</a></p>
  
  <p>I am trying to write a script that executes a custom command on a CSV string variable. The problem is when I define the string variable from another variable(from an array in this case), the bash function is enclosing the elements in single quotes and the command(anothermycommand) is breaking. And if manually define the string variable with a value, it is not enclosing the variable and the custom command(anothermycommand) is working fine when passed to the command.</p>
  
  <pre><code>function myfunction {
      declare  -a ARR=($(mycommand $2 | grep "Server:" | awk '{print $2}')) #variable assignment
      echo ${ARR[@]}
      declare -a ARR=('SERVER-123' 'SERVER-432') #static assignment - Values are same to above varibale assignment
      echo ${ARR[@]}
      declare CSV=$(echo ${ARR[@]}| tr ' ' ',')
      anothermycommand  -t ${CSV}
  </code></pre>
  
  <p>If I use variable assignment (line2) for ${ARR[@]} values, the command is breaking because ${CSV} is enclosed in single quotes. And if I use direct assignment(line4), the command is working fine. I think it is related to array assignments, from line2 the elements are enclosed in single quotes.</p>
  
  <p>For line 3 and 7 bash -x debug</p>
  
  <pre><code>+ echo 'SERVER-123' 'SERVER-432'
  + anothermycommand  -t 'SERVER-123,SERVER-432'
  </code></pre>
  
  <p>For line 5 and 7 bash -x debug</p>
  
  <pre><code>+ echo SERVER-123 SERVER-432
  + anothermycommand  -t SERVER-123,SERVER-432
  </code></pre>
  
  <p>Output of <code>mycommand $2 | grep "Server:" | awk '{print $2}'</code></p>
  
  <pre><code>SERVER-123
  SERVER-432
  </code></pre>
  
  <p>Bash info</p>
  
  <pre><code> $ echo $BASH_VERSION $BASHOPTS
   4.3.48(1)-release checkwinsize:cmdhist:complete_fullquote:expand_aliases:extglob:extquote:force_fignore:interactive_comments:login_shell:progcomp:promptvars:sourcepath
  </code></pre>
  
  <p>How to make this work?</p>