title: OS X bash: dirname
body: <p>I want to create a simple bash script to launch a Java program on OS X. The names of the file, the file path, and the immediate working folder all contain spaces. When I do this:</p>
  
  <pre><code>#!/bin/sh
  cd `dirname $0`
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>usage: dirname path
  </code></pre>
  
  <p>I have also tried putting quotes in all kinds of different places. The most elaborate example being</p>
  
  <pre><code>cd "`dirname \"$0\"`"
  </code></pre>
  
  <p>Nothing has worked. I either get error messages or that cryptic "usage: dirname path" message.</p>
  
  <p>What are other methods that might work?</p>
  
  <hr>
  
  <p><strong>Edit:</strong> this doesn't seem to be an issue for anyone but me so it must just be my box. I'm going to accept my own post below because it's the only solution which worked for this specific problem. However I'm definitely upvoting the solutions which seem to be working for everyone else and really appreciate everyone's help.</p>