Get parent directory of shell script's directory
<p>I have a shell script here:</p>

<pre><code>/node_modules/.bin/exec.sh
</code></pre>

<p>in the exec.sh script, I want to obtain the path of the directory's parent directory that the script is contained in (not pwd/cwd!). I can obtain the containing directory like so:</p>

<pre><code>`dirname $0`
</code></pre>

<p>which will yield:</p>

<pre><code>/node_modules/.bin
</code></pre>

<p>but I am looking to get at one directory higher, I just want to get</p>

<pre><code>/node_modules
</code></pre>

<p>I am having trouble searching for the answer, my guess is:</p>

<pre><code>`dirname $1`
</code></pre>

<p>but just a guess, not sure if that's right at all. Can anyone give an explanation of how to do this and how it works?</p>