title: How to validate filename in bash script?
body: <p><strong>A little bit about my application:</strong></p>
  
  <p>I am writing a small application in bash script. The application must store personal settings to home directory.</p>
  
  <p>My settings are in the form of a key/value pair which will be stored as filename/content:</p>
  
  <pre><code>for example:
  ~/my-github-app
      ├── github-account
      ├── github-token
  </code></pre>
  
  <p><strong>My current solution for adding a key/value:</strong></p>
  
  <pre><code>read KEY
  read VALUE
  # FIXME! should check for for valid filename.
  #        user can do injection hack by KEY="../../path/to/yourfile"
  echo $VALUE &gt; ~/my-github-app/$KEY
  </code></pre>
  
  <p><strong>What is the simplest and safe way to validate $KEY?</strong></p>
  
  <ul>
  <li>A built-in function?  </li>
  <li>A regular expression?</li>
  </ul>
  
  <p><em>I really need a reusable solution, not just for this application.</em></p>
  
  <p>Edit:</p>
  
  <p>"validate filename" mean check string for proper filename format, accepted by OS. </p>
  
  <ul>
  <li>"bob" : good filename format</li>
  <li>""    : bad because filename can not be empty</li>
  <li>"*"   : ?</li>
  <li>"/"   : ?</li>
  <li>"con" : ?
  ....</li>
  </ul>