Skip to content

Latest commit

 

History

History

working-dir

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Working Directory

Here are two helpful tips for finding the working directory.

Called Script Directory

To get the directory hosting a script no matter where you call the script from use this command:

DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)

Git Root Directory

If a directory host a local git project, you can get the root directory by calling this command:

DIR="$(git rev-parse --show-toplevel)"

Reference