Skip to content

Instantly share code, notes, and snippets.

@aminamid
Last active August 29, 2015 14:18
Show Gist options
  • Save aminamid/fd0ada8761ca92851b3f to your computer and use it in GitHub Desktop.
Save aminamid/fd0ada8761ca92851b3f to your computer and use it in GitHub Desktop.
bash get abs dirname of the script
abs_dirname() {
local cwd="$(pwd)"
local path="$1"
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
path="$(readlink "$name" || true)"
done
pwd -P
cd "$cwd"
}
echo "$(abs_dirname "$0")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment