title: How to use the directory a shell script is called from?
body: <p>I am trying to make a script to automate the creation of files and input of certain data in the files, sort of like a template. For example, if the script is called <code>cpp</code> (Just an example, not the actual script name), when I run <code>cpp &lt;filename&gt;</code> it should create a file in the current directory without me having to tell it what the directory is. Right now, I have to hard code a root directory into the script. The basic functionality of the script is something like this (I have validations and stuff, but this is the main function):</p>
  <pre><code>touch &quot;$FILE_PATH&quot; (this is the part that I have to hard code)
  echo -e &quot;#include &lt;bits/stdc++.h&gt;\n\nusing namespace std;\n\nint main() {\n\t\n}&quot; &gt; &quot;$FILEPATH&quot;
  nvim &quot;$FILE_PATH&quot;
  </code></pre>
  <p>In this situation, I have to declare the file path to be <code>FILE_PATH=&quot;$HOME/&lt;a specific directory&gt;/$1.cpp&quot;</code>, meaning when I call on the script, I have to pass an argument relative to the hard-coded location, like perhaps <code>cpp automation/file_manager/shell/apartment</code>. Is there a way for a shell script to automatically find the directory it is called on, so it can be more dynamic and flexible (Go to the directory automation/file_manager/shell/apartment and call <code>cpp apartment</code> to get the same result)? Kind of like vim or neovim, where it creates a file in the current directory.</p>