Skip to content

Instantly share code, notes, and snippets.

@mlawrie
Created October 17, 2012 14:51
Show Gist options
  • Save mlawrie/3905947 to your computer and use it in GitHub Desktop.
Save mlawrie/3905947 to your computer and use it in GitHub Desktop.
bash script current directory following symlinks
#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
DIR="$( dirname "$SOURCE" )"
while [ -h "$SOURCE" ]
do
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
echo $DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment