bash get directory of file - How can I get the source directory of a Bash script from within the script itself?

bash script path / bash / directory

How do I get the path of the directory in which a Bash script is located, inside that script?

I want to use a Bash script as a launcher for another application. I want to change the working directory to the one where the Bash script is located, so I can operate on the files in that directory, like so:

$ ./application

19 revs, 14 users 34%



Answer #1
#!/bin/bash

scriptdir=`dirname "$BASH_SOURCE"`