title: In Bash, how to find the lowest-numbered unused file descriptor?
body: <p>In a Bash-script, is it possible to open a file on "the lowest-numbered file descriptor not yet in use"?</p>
  
  <p>I have looked around for how to do this, but it seems that Bash always requires you to specify the number, e.g. like this:</p>
  
  <pre><code>exec 3&lt; /path/to/a/file    # Open file for reading on file descriptor 3.
  </code></pre>
  
  <p>In contrast, I would like to be able to do something like</p>
  
  <pre><code>my_file_descriptor=$(open_r /path/to/a/file)
  </code></pre>
  
  <p>which would open 'file' for reading on the lowest-numbered file descriptor not yet in use and assign that number to the variable 'my_file_descriptor'.</p>