title: Extract filename and extension in Bash
body: <p>I want to get the filename (without extension) and the extension separately.</p>
  
  <p>The best solution I found so far is:</p>
  
  <pre><code>NAME=`echo "$FILE" | cut -d'.' -f1`
  EXTENSION=`echo "$FILE" | cut -d'.' -f2`
  </code></pre>
  
  <p>This is wrong because it doesn't work if the file name contains multiple <code>.</code> characters. If, let's say, I have <code>a.b.js</code>, it will consider <code>a</code> and <code>b.js</code>, instead of <code>a.b</code> and <code>js</code>.</p>
  
  <p>It can be easily done in Python with</p>
  
  <pre><code>file, ext = os.path.splitext(path)
  </code></pre>
  
  <p>but I'd prefer not to fire up a Python interpreter just for this, if possible.</p>
  
  <p>Any better ideas?</p>