title: Using "expanding characters" in a variable in a bash script
body: <p>I apologize beforehand for this question, which is probably both ill formulated and answered a thousand times over. I get the feeling that my inability to find an answer is that I don't quite know how to ask the question.</p>
  <p>I'm writing a script that traverses folders in a bunch of mounted external hard drives, like so:</p>
  <p><code>for g in /Volumes/compartment-?/{Private/Daniel,Daniel}/Projects/*/*</code></p>
  <p>It then proceeds to perform long-running tasks on each of the directories found there. Because these operations are io-intensive rather than cpu-intensive, I thought I'd add the option to provide which &quot;compartment&quot; I want to work in, so that I can parallelize the workloads.</p>
  <p>But, doing</p>
  <pre><code>cmp=&quot;?&quot;
  [[ ! &quot;$1&quot; = &quot;&quot; ]] &amp;&amp; cmp=&quot;$1&quot;
  </code></pre>
  <p>And then,
  <code>for g in /Volumes/compartment-$cmp/{Private/Daniel,Daniel}/Projects/*/*</code></p>
  <p>Doesn't work - the question mark that should expand to all compartments instead becomes literal, so I get an error that &quot;compartment-?&quot; doesn't exist, which is of course true.</p>
  <p>How do I create a variable with a value that &quot;expands,&quot; like <code>dir=&quot;./*&quot;</code> working with <code>ls $dir</code>?</p>
  <p>EDIT: Thanks to @dan for the answer. I was brought up to be courteous and thank people, so I did thank him for it in a comment on his question, but that comment has been removed, and I'm anxious that repeating it might be some kind of infraction here. I ended up simply escaping my question mark glob character, i.e. <code>\?</code>, since for this script I only need to either search all drives or one particular drive. But I'll keep the answer handy for the next time I write a script where I'd like to support more advanced arguments.</p>