title: Wildcard single file
body: <p>Given the following files</p>
  
  <pre class="lang-sh prettyprint-override"><code>$ ls
  bar.txt  baz.txt  qux.txt
  </code></pre>
  
  <p>I would like to save only the first <code>txt</code> file to a variable. I tried this</p>
  
  <pre><code>$ var=*.txt
  </code></pre>
  
  <p>but it just saves all files</p>
  
  <pre><code>$ echo $var
  bar.txt baz.txt qux.txt
  </code></pre>
  
  <p>I would like to do this using a wildcard if possible, and <code>extglob</code> is okay. The files here do not have spaces in the name but I would like the solution to also work for files with spaces.</p>
  
  <p>After using <a href="https://stackoverflow.com/a/15827364">kamituel’s answer</a> I realized that this can work too</p>
  
  <pre class="lang-sh prettyprint-override"><code>$ set *.txt
  
  $ echo $1
  bar.txt
  </code></pre>