title: What is the difference between ${var}, "$var", and "${var}" in the Bash shell?
body: <p>What the title says: what does it mean to encapsulate a variable in <code>{}</code>, <code>""</code>, or <code>"{}</code>"? I haven't been able to find any explanations online about this - I haven't been able to refer to them except for using the symbols, which doesn't yield anything.</p>
  
  <p>Here's an example:</p>
  
  <pre><code>declare -a groups
  
  groups+=("CN=exampleexample,OU=exampleexample,OU=exampleexample,DC=example,DC=com")
  groups+=("CN=example example,OU=example example,OU=example example,DC=example,DC=com")
  </code></pre>
  
  <p>This:</p>
  
  <pre><code>for group in "${groups[@]}"; do
      echo $group
  done
  </code></pre>
  
  <p>Proves to be much different than this:</p>
  
  <pre><code>for group in $groups; do
      echo $group
  done
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>for group in ${groups}; do
      echo $group
  done
  </code></pre>
  
  <p>Only the first one accomplishes what I want: to iterate through each element in the array. I'm not really clear on the differences between <code>$groups</code>, <code>"$groups"</code>, <code>${groups}</code> and <code>"${groups}"</code>. If anyone could explain it, I would appreciate it.</p>
  
  <p>As an extra question - does anyone know the accepted way to refer to these encapsulations?</p>