title: Deferred evaluation of bash variables
body: <p>I need to define a string (<code>options</code>) which contains a variable (<code>group</code>) that is  going to be available later in the script.</p>
  
  <p>This is what I came up with, using a literal string that gets evaluated later.</p>
  
  <pre><code>#!/bin/bash
  
  options='--group="$group"' #$group is not available at this point
  
  #
  # Some code...
  #
  
  group='trekkie'
  eval echo "$options" # the result is used elsewhere
  </code></pre>
  
  <p>It works, however it makes use of <code>eval</code> which I would like to avoid if not absolutely necessary (I don't want to risk potential problems because of unpredictable data).</p>
  
  <p>I've asked for help in multiple places and I've got a couple of answers that were directing me to use <a href="http://mywiki.wooledge.org/BashFAQ/006" rel="nofollow noreferrer">indirect variables</a>.</p>
  
  <p>The problem is I simply fail to see how indirect variables might help me with my problem. As far as I understand they only offer a way of indirectly referencing other variables like this:</p>
  
  <pre><code>options="--group="$group""
  a=options
  group='trekkies'
  echo "${!a}" # spits out --group=
  </code></pre>
  
  <p>I would also like to avoid using functions if possible because I don't want to make things more complicated than they need to be.</p>