2015-10-02
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).
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";
1.0.0 -- 2015-10-02