I am trying to obtain the absolute path to the currently running script on OS X.
I saw many replies going for readlink -f $0. However since OS X\'s
readlink -f $0
abs_path () { echo "$(cd $(dirname "$1");pwd)/$(basename "$1")" }
dirname will give the directory name of /path/to/file, i.e. /path/to.
dirname
/path/to/file
/path/to
cd /path/to; pwd ensures that the path is absolute.
cd /path/to; pwd
basename will give just the filename in /path/to/file, i.e.file.
basename
file