title: Simple Bash - for f in *
body: <p>Consider this simple loop:</p>
  
  <pre><code>for f in *.{text,txt}; do echo $f; done
  </code></pre>
  
  <p>I want to echo ONLY valid file names. Using the $f variable in a script everything works great unless there aren't any files of that extension. In the case of an empty set, $f is set to *.text and the above line echos:</p>
  
  <pre><code>*.text
  *.txt
  </code></pre>
  
  <p>rather than echoing nothing. This creates an error if you are trying to use $f for anything that is expecting an actual real file name and instead gets *. </p>
  
  <p>If there are any files that match the wildcard so that it is not an empty set everything works as I would like. e.g.</p>
  
  <pre><code>123.text
  456.txt
  789.txt
  </code></pre>
  
  <p>How can I do this without the errors and without seemingly excessive complexity of first string matching $f for an asterisk?</p>