title: Change directory to path of parent/calling script in bash
body: <p>I have dozens of scripts, all in different directories. (exported/expanded Talend jobs)</p>
  
  <p>At this moment each job has 1 or 2 scripts, starting with the same lines, most important one:</p>
  
  <pre><code>CD ***path-to-script***
  </code></pre>
  
  <p>and several lines to set the Java path and start the job.</p>
  
  <p>I want to create a script, which will be ran from all these scripts.
  e.g.:</p>
  
  <pre><code>/scripts/talend.sh
  </code></pre>
  
  <p>And in all talend scripts, the first line will run <code>/scripts/talend.sh</code>, some examples of where these scripts are ran from:</p>
  
  <pre><code>/talend-job1_0.1/talend-job1_0.1/talend-job1/talend-job1.sh
  /talend-task2_0.1/talend-task2_0.1/talend-task2/talend-task2.sh
  /talend-job3_0.1/talend-job3_0.1/talend-job3/talend-job3.sh
  </code></pre>
  
  <p>How can I determine where the <code>/scripts/talend.sh</code> is started from, so I can CD to that path from within <code>/scripts/talend.sh</code>.</p>
  
  <p>The Talend scripts are not run from within the directory itself, but from a cronjob, or a different users home directory.</p>
  
  <p>EDIT:
  The question was marked as duplicate, but <a href="https://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in">Getting the source directory of a Bash script from within</a> is not answering my question 100%.
  Problem is:
   - The basic script is being called from different scripts
   - Those different scripts can be run from command line, with, and with or without a symbolic link.
   - The $0, the $BASH_SOURCE and the pwd all do some things, but no solution mentioned covers all the difficulties.</p>
  
  <p>Example:</p>
  
  <pre><code>/scripts/talend.sh   
  </code></pre>
  
  <p>In this script I want to configure the $PATH and $HOME_PATH of Java, and CD to the place where the Talend job is placed. (It's a package, so that script MUST be run from that location).</p>
  
  <p>Paths to the jobs are, for example:</p>
  
  <pre><code>/u/talend/talendjob1/sub../../talendjob1.sh 
  /u/talend/talendjob2/sub../../talendjob2.sh
  /u/talend/talendjob3/sub../../talendjob3.sh
  </code></pre>
  
  <p>Multiple jobs are run from a TMS application. This application cannot run these scripts with the whol name (to long, name can only be 6 long), so in a different location I have symbolic links:</p>
  
  <pre><code>/u/tms/links/p00001 -&gt; /u/talend/talendjob1/sub../../talendjob1.sh
  /u/tms/links/p00002 -&gt; /u/talend/talendjob1/sub../../talendjob2.sh
  /u/tms/links/p00003 -&gt; /u/talend/talendjob1/sub../../talendjob3.sh
  /u/tms/links/p00004 -&gt; /u/talend/talendjob1/sub../../talendjob4.sh
  </code></pre>
  
  <p>I think you get an overview of the complexity and why I want only one basic talend script, where I can leave all basic stuff. But I only can do that, if I know the source of the Talend script, because there I have to be to start that talend job.</p>