lingtalfi / printScriptDir

get the bash script's real directory
6 stars 1 forks source link

printScriptDir

2015-10-02

What is it?

The printScriptDir function returns the real directory from which a bash script is executed.

It handles:

- symlinks
- relative paths 
----- including normalization (converting ../../ into a resolved path)
- absolute paths

I tested it on MacOsX and Linux (debian8).

How to use it?

Copy/paste the printScriptDir function in your script. Then you can do one of the following:

# display it
printScriptDir "$0"
# or store it in a variable
realDir=$(printScriptDir "$0")
echo "realDir=$realDir";

History Log